You are on page 1of 3

px=[-5 9 4 10];

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 =

[-125, 25, -5, 1]

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 =

[1000, 100, 10, 1]

coef=[p1;p2;p3;p4]

coef =

[-125, 25, -5, 1]


[ 729, 81, 9, 1]
[ 64, 16, 4, 1]
[1000, 100, 10, 1]

const=py'

const =

7
0
1
3

X=coef\const
X =

1/30
-7/30
-8/5
9

X=X'

X =

[1/30, -7/30, -8/5, 9]

X=[1/30, -7/30, -8/5, 9]

X =

0.0333 -0.2333 -1.6000 9.0000

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 =

[-1/4, 1/2, 63/4]

Z=[-1/4, 1/2, 63/4]

Z =

-0.2500 0.5000 15.7500

y1=polyval(Z,z);
plot(z,y1)
 

You might also like