y|[gۑiTj𓚗z

 

1D

vO

x=-10:0.01:10;

y1=zeros(size(x));

y2=zeros(size(x));

n1=4;

n2=10;

 

for i=1:n1

  y1=y1+(-1)^i*sin(i*x)/i;

end

y1=y1*2/pi;

 

for i=1:n2

  y2=y2+(-1)^(i)*sin(i*x)/i;

end

y2=y2*2/pi;

 

plot(x,y1,x,y2)

legend('n=4','n=10')

grid('on')

s

 

2D

vO

x=-10:2:8;

y=[-970 -510 -202 -59 -9 3 15 65 212 513];

p1=polyfit(x,y,1)

x1=-10:0.1:8;

y1=polyval(p1,x1);

p2=polyfit(x,y,2)

y2=polyval(p2,x1);

p3=polyfit(x,y,3)

y3=polyval(p3,x1);

plot(x,y,'o',x1,y1,x1,y2,x1,y3)

legend('data','1st', '2nd', '3rd')

grid('on')

p1 =

   60.515  -33.685

 

p2 =

   -2.8835   54.7481   58.5879

 

p3 =

    0.980842   0.059003   0.213287    2.091375