Write a userdefined MATLAB function that fits data points to
Write a user-defined MATLAB function that fits data points to a power function of the form y = bx\"\'. Name the function [b, m] = powerfit(x, y), where the input arguments x and y are vectors with the coordinates of the data points, and the output arguments b and m are the constants of the fitted power equation. Use the function to fit the data below. Make a plot that shows the data points and the function.
Solution
function [b m] = PowerFit(x, y) % x, y : vectors with the coordinates of the data points. % b m are the values of the coefficients % y = bx^m % ln(y) = ln(b) + m*ln(x); % Y = B + m*X; X = log(x); Y = log(y); [B M] = linearLeastSquare(X, Y); b = exp(B); m = M; end