Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- close()
- clear
- clc
- x=[6 8 16 49];
- y=[2.5 11.35 31.01 49.9];
- n=length(x);
- A=[n sum(x) sum(x^2) sum(x^3); sum(x) sum(x^2) sum(x^3) sum(x^4);sum(x^2) sum(x^3) sum(x^4) sum(x^5); sum(x^3) sum(x^4)sum(x^5) sum(x^6)];
- Y1=[sum(y); sum(y.*x); sum(y.*x^2); sum(y.*x^3)];
- P=inv(A)*Y1
- for i=1:n
- mprintf(" p%i= %f ",i,P(i))
- end
- z=0:0.01:50;
- deff('[yk]=fun1(z)','yk=P(1)+P(2)*z+P(3)*z^2+P(4)*z^3')
- plot(z,fun1(z),x,y,'o')
- xlabel('x')
- ylabel('y(x)')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement