0% found this document useful (0 votes)
51 views5 pages

U U U U U U U U U U U U

4 ±1 4 . N=[5,11,21]; t=[-5:0.01:5]; for k=1:3 i=[0:N(k)]; x=-5+i.*10./N(k); y=1./(1+x.^2); p=polyfit(x,y,N(k)); subplot(2,2,k) plot(t,polyval(p,t)); title(['P_{' int2str(N(k)) '}']); set(gca,'ytick ',[-0.5:0.5:1.5]); set(gca,'xtick',[ -5:1:5]); axis([-5 5 -0.5 1.5]); xlabel('x'); ylabel('f(x)'); end subplot(2,2,4); plot(t,1./(1+t.^2)); set(gca,'ytick',[ -0.5:0.5:1.5]); set(gca,'xtick',[ -5:1:5]); xlabel('x'); ylabel('f(x)'); title('(1+x^2)^{ -1}'); axis([-5 5 -0.5 1.5]); P5 1.5 1.5 P 11 1 1

Uploaded by

yoavram
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views5 pages

U U U U U U U U U U U U

4 ±1 4 . N=[5,11,21]; t=[-5:0.01:5]; for k=1:3 i=[0:N(k)]; x=-5+i.*10./N(k); y=1./(1+x.^2); p=polyfit(x,y,N(k)); subplot(2,2,k) plot(t,polyval(p,t)); title(['P_{' int2str(N(k)) '}']); set(gca,'ytick ',[-0.5:0.5:1.5]); set(gca,'xtick',[ -5:1:5]); axis([-5 5 -0.5 1.5]); xlabel('x'); ylabel('f(x)'); end subplot(2,2,4); plot(t,1./(1+t.^2)); set(gca,'ytick',[ -0.5:0.5:1.5]); set(gca,'xtick',[ -5:1:5]); xlabel('x'); ylabel('f(x)'); title('(1+x^2)^{ -1}'); axis([-5 5 -0.5 1.5]); P5 1.5 1.5 P 11 1 1

Uploaded by

yoavram
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

4 ‫ – תרגיל‬1 ‫אנליזה נומרת‬

‫יואב רם‬
4 ‫שאלה‬

.‫ב‬-‫א‬

N=[5,11,21];
t=[-5:0.01:5];
for k=1:3
i=[0:N(k)];
x=-5+i.*10./N(k);
y=1./(1+x.^2);
p=polyfit(x,y,N(k));
subplot(2,2,k)
plot(t,polyval(p,t));
title(['P_{' int2str(N(k)) '}']);
set(gca,'ytick',[-0.5:0.5:1.5]);
set(gca,'xtick',[-5:1:5]);
axis([-5 5 -0.5 1.5]);
xlabel('x');
ylabel('f(x)');
end
subplot(2,2,4);
plot(t,1./(1+t.^2));
set(gca,'ytick',[-0.5:0.5:1.5]);
set(gca,'xtick',[-5:1:5]);
xlabel('x');
ylabel('f(x)');
title('(1+x^2)^{-1}');
axis([-5 5 -0.5 1.5]);
P5 P11
5.1 5.1

1 1

5.0 5.0
)x(f

)x(f

0 0

5.0- 5.0-
5- 4- 3- 2- 1- 0 1 2 3 4 5 5- 4- 3- 2- 1- 0 1 2 3 4 5
x x

P12 x+1( 21-


)
5.1 5.1

1 1

5.0 5.0
)x(f

)x(f

0 0

5.0- 5.0-
5- 4- 3- 2- 1- 0 1 2 3 4 5 5- 4- 3- 2- 1- 0 1 2 3 4 5
x x

1
.‫ג‬
6
10 ( 6)
max ( f ( x ) ) ∙
5 720 ∙ 64 2
N=5 : max f (6) ( x )=720 ,|E5|≤∨ −5 ≤ x≤ 5 ∨¿ =2
−5≤ x ≤5 6 ! ∙ 4 ∙6 720 ∙ 4 ∙ 6 3

10 12
max ( f (12) ( x ) ) ∙
( 12 ) 8 −5 ≤ x ≤5 11 3.35701∙ 108 ∙0.56447393
N=11: max f (x)≈ 3.35701∙ 10 ,|E11|≤∨ ∨≈ ≈ 8.242∙ 10−
−5 ≤x ≤5 12 ! ∙ 4 ∙ 12 479001600 ∙ 4 ∙ 12

10 22
max ( f (22) ( x ) ) ∙
21 1.124 ∙ 1021 ∙ 8.15 ∙10−8
N=21: max f ( 22) ( x)≈ 1.124 ∙1021 ,| E21|≤∨ −5≤ x ≤5 ∨≈ 21
≈ 9.2614 ∙ 10−10
−5 ≤ x ≤5 22! ∙ 4 ∙22 1.124 ∙ 10 ∙ 4 ∙ 22

.‫ד‬

piecewise linear N=5 piecewise linear N=11


1.5 1.5

1 1
f(x)
f(x)

0.5 0.5

0 0

-0.5 -0.5
-5 -4 -3 -2 -1 0 1 2 3 4 5 -5 -4 -3 -2 -1 0 1 2 3 4 5
x x
piecewise linear N=21 (1+x 2)-1
1.5 1.5

1 1
f(x)
f(x)

0.5 0.5

0 0

-0.5 -0.5
-5 -4 -3 -2 -1 0 1 2 3 4 5 -5 -4 -3 -2 -1 0 1 2 3 4 5
x x

2
N=[5,11,21];
xi=[-5:0.01:5];
for k=1:3
i=[0:N(k)];
x=-5+i.*10./N(k);
y=1./(1+x.^2);
yi=interp1(x,y,xi,'linear');
subplot(2,2,k)
plot(xi,yi);
title(['piecewise linear N=' int2str(N(k))]);
set(gca,'ytick',[-0.5:0.5:1.5]);
set(gca,'xtick',[-5:1:5]);
axis([-5 5 -0.5 1.5]);
xlabel('x');
ylabel('f(x)');
end
subplot(2,2,4);
plot(xi,1./(1+xi.^2));
set(gca,'ytick',[-0.5:0.5:1.5]);
set(gca,'xtick',[-5:1:5]);
xlabel('x');
ylabel('f(x)');
title('(1+x^2)^{-1}');
axis([-5 5 -0.5 1.5]);

.‫ה‬

piecewise cubic N=5 piecewise cubic N=11


1.5 1.5

1 1
f(x)
f(x)

0.5 0.5

0 0

-0.5 -0.5
-5 -4 -3 -2 -1 0 1 2 3 4 5 -5 -4 -3 -2 -1 0 1 2 3 4 5
x x
piecewise cubic N=21 (1+x 2)-1
1.5 1.5

1 1
f(x)
f(x)

0.5 0.5

0 0

-0.5 -0.5
-5 -4 -3 -2 -1 0 1 2 3 4 5 -5 -4 -3 -2 -1 0 1 2 3 4 5
x x

3
N=[5,11,21];
xi=[-5:0.01:5];
for k=1:3
i=[0:N(k)];
x=-5+i.*10./N(k);
y=1./(1+x.^2);
yi=interp1(x,y,xi,'pchip');
subplot(2,2,k)
plot(xi,yi);
title(['piecewise cubic N=' int2str(N(k))]);
set(gca,'ytick',[-0.5:0.5:1.5]);
set(gca,'xtick',[-5:1:5]);
axis([-5 5 -0.5 1.5]);
xlabel('x');
ylabel('f(x)');
end
subplot(2,2,4);
plot(xi,1./(1+xi.^2));
set(gca,'ytick',[-0.5:0.5:1.5]);
set(gca,'xtick',[-5:1:5]);
xlabel('x');
ylabel('f(x)');
title('(1+x^2)^{-1}');
axis([-5 5 -0.5 1.5]);

5 ‫שאלה‬

.‫ג‬-‫א‬

n=10;
t=[-5:0.01:5];
% equally spaces points
i=[0:n];
x=t(1)+i.*(t(end)-t(1))./n;
yx=1./(1+25.*x.^2);
pesp=polyfit(x,yx,n);

% chebyshev points
xcheb=cos((2.*i+1)*pi/(2*n));
yxcheb=1./(1+25.*xcheb.^2);
pcheb=polyfit(xcheb,yxcheb,n);

yt=1./(1+25.*t.^2) ;
pespt=polyval(pesp,t);
pchebt=polyval(pcheb,t./5);
subplot(2,1,1);
plot(t,[yt; pespt;pchebt]);
legend('1/(1+25x^2)','eq. spaces pts. approx.','chebyshev pts.
approx.','location','north')
xlabel('x');
ylabel('f(x)');
title('Approx. by equally spaces poitns and by Chebyshev points');
subplot(2,1,2);
plot(t,[abs(yt-pespt);abs(yt-pchebt)]);
legend('eq. spaces approx. error','chebyshev approx
error','location','north');
xlabel('x');
ylabel('error');
title('Approx. error for equally spaces points and Chebyshev
points');

4
‫‪stniop vehsybehC yb dna sntiop secaps yllauqe yb .xorppA‬‬
‫‪6‬‬
‫‪2‬‬
‫‪x52+1(/1‬‬ ‫)‬
‫‪.xorppa .stp secaps .qe‬‬
‫‪4‬‬ ‫‪.xorppa .stp vehsybehc‬‬

‫‪2‬‬
‫‪)x(f‬‬

‫‪0‬‬

‫‪2-‬‬
‫‪5-‬‬ ‫‪4-‬‬ ‫‪3-‬‬ ‫‪2-‬‬ ‫‪1-‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪2‬‬ ‫‪3‬‬ ‫‪4‬‬ ‫‪5‬‬
‫‪x‬‬

‫‪stniop vehsybehC dna stniop secaps yllauqe rof rorre .xorppA‬‬


‫‪6‬‬
‫‪rorre .xorppa secaps .qe‬‬
‫‪5‬‬ ‫‪rorre xorppa vehsybehc‬‬

‫‪4‬‬

‫‪3‬‬
‫‪rorre‬‬

‫‪2‬‬

‫‪1‬‬

‫‪0‬‬
‫‪5-‬‬ ‫‪4-‬‬ ‫‪3-‬‬ ‫‪2-‬‬ ‫‪1-‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪2‬‬ ‫‪3‬‬ ‫‪4‬‬ ‫‪5‬‬
‫‪x‬‬

‫ד‪.‬‬

‫מהגרף התחתון ברור כי למרות שבנק' מסוימות האינטרפולציה ע"י נק' שוות מרחק טוב יותר‪ ,‬הרי‬
‫שאלו תמיד נק' האינטרפולציה‪ ,‬ובסה"כ הקירוב ע"י נק' צבישב טוב הרבה יותר‪ ,‬בעיקר בנק' שערכיהן‬
‫המוחלטים גדולים מ‪ ,2-‬כלומר בעיקר בצדדי הקטע‪ ,‬ובכל מקרה הקירוב ע"י נק' צ'בישב מקבל‬
‫שגיאה הקטנה מ‪ 1-‬בעוד הקירוב ע"י נק' שוות מרחק מקבל שגיאה הקטנה מ‪ 6-‬וגדולה מ‪ 1-‬ב‪20%-‬‬
‫מהקטע המדובר‪.‬‬

‫‪5‬‬

You might also like