CS计算机代考程序代写 matlab xdata=[0.075 0.5 1.0 1.2 1.7 2.0 2.3]

xdata=[0.075 0.5 1.0 1.2 1.7 2.0 2.3]
ydata=[600 800 1200 1400 2050 2650 3750]

N=length(xdata);

A=[N sum(xdata) sum(xdata.^2) ;
sum(xdata) sum(xdata.^2) sum(xdata.^3);
sum(xdata.^2) sum(xdata.^3) sum(xdata.^4)];

C=[sum(ydata);
sum(xdata.*ydata);
sum(xdata.^2.*ydata)];

%
%Note that for brevity I have used the MATLAB linsolve() function
%solve the resulting equation. You can use any of the
%solvers from previous lectures.
%
a=linsolve(A,C);

x=linspace(0,2.5);
y=a(1)+a(2)*x+a(3)*x.^2;

hold off
plot(xdata,ydata,’ko’,’MarkerSize’,20,’MarkerFaceColor’,’r’)
hold on
plot(x,y,’b-‘,’LineWidth’,2);
xlabel(‘x’);
ylabel(‘y’);

%
% p=polyfit(xdata,ydata,2)
% ymatlab=polyval(p,x)
% hold off
% plot(xdata,ydata,’ko’,x,ymatlab)