Professional Documents
Culture Documents
py=[7 0 1 3];
scatter(x,y,'filled')
Unrecognized function or variable 'x'.
scatter(px,py,'filled')
syms x
polin=[x^3 x^2 x 1];
p1=subs(polin,x,-5)
p1 =
p2=subs(polin,x,9)
p2 =
[729, 81, 9, 1]
p3=subs(polin,x,4)
p3 =
[64, 16, 4, 1]
p4=subs(polin,x,10)
p4 =
coef=[p1;p2;p3;p4]
coef =
const=py'
const =
7
0
1
3
X=coef\const
X =
1/30
-7/30
-8/5
9
X=X'
X =
X =
z=linspace(-20,20);
y=polyval(X,z);
plot(z,y), grid on
hold on
scatter(px,py,'filled')
mx=[-5 9 3];
my=[7 0 15];
pol=[x^2 x 1];
q1=subs(pol,x,-5)
q1 =
[25, -5, 1]
q2=subs(pol,x,9)
q2 =
[81, 9, 1]
q3=subs(pol,x,3)
q3 =
[9, 3, 1]
coefic=[q1;q2;q3]
coefic =
[25, -5, 1]
[81, 9, 1]
[ 9, 3, 1]
consta=my'
consta =
7
0
15
Z=coefic\consta
Z =
-1/4
1/2
63/4
Z=Z'
Z =
Z =
y1=polyval(Z,z);
plot(z,y1)