Can someone help me with this MATLAB problem? Make a plot for each curve fit (a)
ID: 3819987 • Letter: C
Question
Can someone help me with this MATLAB problem?
Make a plot for each curve fit (a)-(d) (as lines) with the given data as symbols (use subplot to have all plots in one figure). (a) Curve fit the data with a linear regression line. (b) Curve fit the data with a 2^nd-order polynomial. (c) Curve fit the data with a 4^th-order polynomial. (d) Plant growth can be modeled as an exponential function called the "logistic equation" H(t) = C/(l + A = e^-B t), where H is the height, C is a maximum value for H, A and B are constants, and t is the number of weeks. The equation can be rewritten in the form (C/H) - 1 = A middot e^-B t, and linearized to ln{{C/H) - 1) = ln A - B middot t. Assuming C = 254cm. determine the constants A and B with least squares fitting. (e) Measure the quality of the least-squares fit for EACH model (a)-(d) by computing the "Coefficient of Determination". Print the results in a FORMATTED TABLE. (f) Discuss the differences in visual fit between the graphs from (a)-(c) AND the results for the "Coefficient of Determination". Which fit is the best? Why?Explanation / Answer
x = [1 3 5 7 9 11 13];
y = [22 51 127 202 227 248 252];
function y = f(constant,x)
y = constant(1)*x+constant(2);
end
constant = lsqcurvefit(@f,[0:0],x,y);
m = constant(1);
c = constant(2);
xfit = 0:0.1:10;
yfit = f(constant,xfit);
figure
plot(x,y,'b*')
hold on
plot(xfit,yfit,'r','linewidth',2)
grid on
For different subparts:::
% linear fit
function y = f(constant,x)
y = constant(1)*x+constant(2);
end
constant = lsqcurvefit(@f,[0:0],x,y);
m1 = constant(1);
c1 = constant(2);
% quadratic fit
function y = f(constant,x)
y = constant(1)*x.^2+constant(2)*x+constant(3);
end
constant = lsqcurvefit(@f,[0:0:0],x,y);
a1 = constant(1);
b1 = constant(2);
c1 = constant(3);
%4th order polynomial
function y = f(constant,x)
y = constant(1)*x.^4+constant(2)*x.^3+constant(3)*x.^2+constant(4)*x+constant(5);
end
constant = lsqcurvefit(@f,[0:0:0:0:0],x,y);
a1 = constant(1);
b1 = constant(2);
c1 = constant(3);
d1 = constant(4);
e1 = constant(5);
Note::
Function definition should be written in different file
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.