for each of the bases b= 1.2345, 3, 7 construct a function f(x) such that: f(b^x)=x in matlab

To construct a function in MATLAB that can transform a given base to its corresponding exponent, you can use the logarithmic functions. Here's an example function f that takes the base b and returns the exponent x such that f(b^x) = x:

main.m
function x = f(b)
    % Compute the exponent x using logarithm and base conversion
    x = log(1:b) / log(b);
end
114 chars
5 lines

The function uses the property that for any positive base b, b^x can be rewritten as exp(x * log(b)). We can then take the natural logarithm of b^x and divide it by the natural logarithm of b to obtain the exponent x. Note that log in MATLAB represents the natural logarithm.

Now you can use this f function by passing the desired base b as an argument. For example:

main.m
b = 1.2345;
x = f(b);
disp(x);
31 chars
4 lines

This will print the corresponding exponent x for the base b according to the equation f(b^x) = x. You can do the same for other bases such as 3 and 7.

gistlibby LogSnag