Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a user defined function that fits data points to an exponential function o

ID: 3539339 • Letter: W

Question

write a user defined function that fits data points to an exponential function of the form y=be^(mx). Name the function[b,m]=expofit(x,y), where the inputs arguments x and y are vectors with coordinates of the data points, and the output arguments b and m are constants of the fitted power equation. also make sure that your function makes plot that shows data points in circle markers and the fitted curve with solid line. Test your funcion with the following data. x=[0,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0] and y=[6.0,4.83,3.70,3.15,2.41,1.83,1.49,1.21,0.96,0.73,0.64]

Explanation / Answer

function [b,m]=expofit(x,y)

pp = polyfit(x,log(y),1);

pp(2)=exp(pp(2));

b=pp(2);

m=pp(1);

plot(x,y,'bo'); hold on; %plot your raw data

plot(x,(b*exp(m*x)),'r-');

end