Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
ד"בס
באינטרפולציהתרגיל כיתה
:ותהבא האינטרפולציהנקודות נותנתו .1x = 0: .1: 5; y=sin(x)./(1+x); z=sin(3*x)./(1+x); u=1./(1+25*x.^2);
:Matlab בעזרת הפקודות המתאמות ב
(x,u) ,(x,z) ,(x, y)עבור 8ו 4ממעלה האינטרפולציות פולינומים מצא את .א
) : בנקודות הבאותאינטרפולציות של פולינומים הערכי מצא את .ב
)
בנקודות האינטרפולציה לכול הפולינומים SSE חישב .ג CHEBYSHEVחישב קירוב לשלושת פונקציות האלה בנקודות האינטרפולציה של .ד
: תשובה
p = polyfit(x,y,4); f = polyval(p,x); plot(x,y,’o’,x,f,’-r’)
y=sin(3*x)./(1+x); p = polyfit(x,y,4); f = polyval(p,x); plot(x,y,’o’,x,f,’-r’)
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
p = polyfit(x,y,8); f = polyval(p,x); plot(x,y,’o’,x,f,’-r’)
hold on; ezplot(‘sin(3*x)./(1+x)’,[-0.9 6]); xx=-2:0.1:7; yy=polyval(p,xx); plot(xx,yy, ‘r’,’LineWidth’,3);
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 1 2 3 4 5 6
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
x
sin ( 3 x )./( 1 + x )
. ש ב סע ף ד
N = 21; k = 0:N-1; x = cos( (pi*(N-k-0.5))/N); y = 1./(1+25*x.^2); for i = 1:N % the polynomial whose roots are all the values of X except this one w = poly(x( (1:N) ~= i)); % scale with correspondes to Lagrange formula pvals(i,:) = w ./ polyval(w, x(i)); end % the final Lagrange polynomial LN = y*pvals; xi = [-1:0.01:1]; yi = polyval(LN,xi); zi = 1./(1+25*xi.^2); hi = abs(zi-yi); subplot(1,2,1); plot(xi,yi,'g',xi,zi,'r--',x,y,'o'); grid; legend('P_n(x)','f(x)','Chebyshev nodes','Location', 'NorthWest'); subplot(1,2,2); plot(xi,hi,'r'); legend('Interpolation error');
p= poly(-7:7) צייר גרף של פולינום .2 polyval(p,6.5:8.5)מצא ערכים .א ? על איכות של קירוב בקצבות רמה ניתן לאומ .ב
ezplot('polyval(poly(-7:7),x)')
עבור הנתונים הבאים .3
x = 0:.1:1;
y = [-0.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30 11.2];
-1 -0.5 0 0.5 10
0.5
1
1.5
2
2.5
3
Pn(x)
f(x)
Chebyshev nodes
-1 -0.5 0 0.5 10
0.5
1
1.5
2
2.5x 10
-8
Interpolation error
-6 -4 -2 0 2 4 6
-3
-2
-1
0
1
2
3
x 108
x
x (x2-1) (x2-4) (x2-9) (x2-16) (x2-25) (x2-36) (x2-49)
11ו 2ממעלה האינטרפולציות פולינומים מצא וצייר את .א בשני מקרים הבאים SSEחישב .ב ? מה היא הצורה מדויקת של הניסוי בצורה פולינומיאלי .ג
p = polyfit(x,y,2); xi = linspace(0,1,100);
yi = polyval(p,xi); pp = polyfit(x,y,10); y10 = polyval(pp,xi);
plot(x,y,'o',xi,yi,'--',xi,y10) xlabel('x'), ylabel('y=f(x)')
title('2nd and 10th Order Curve Fitting')
MATLABתנו הסבר לפקודות הבאות ב .4
% interpolation s=interp1(x,y,x0 ,'linear') % linear interpolation s=interp1(x,y,x0,'cubic') % cubic interpolation s=interp1(x,y,x0,'spline') % cubic spline interpolation s=interp1(x,y,x0,'nearest') % nearest neighbor interpolation s=polyfit(x,y,n)
% polynomial of order n interpolation