Contents
1. feladat
g=9.80665;
a=16;
f=@(t,y)[y(2);g*(1-a*y(1).^3)];
[t,y]=ode45(f,[0,2],[0.1,0]);
plot(t,y(:,1))
ampl=(max(y(:,1))-min(y(:,1)))/2
merules=@(ido)interp1(t,y(:,1),ido)-0.3;
periodus=fzero(merules,1)-fzero(merules,0.2)
ampl =
0.24694
periodus =
0.81697
2. feladat
g=9.80665;
L=0.5;
k=40;
m=0.25;
f=@(t,y)[y(2);y(1).*y(4).^2+g*cos(y(3))-k/m*(y(1)-L);y(4);(-2*y(2)*y(4)-g*sin(y(3)))/y(1)];
[t,y]=ode45(f,[0,2],[L,0,pi/3,0]);
figure(1)
plot(t,y(:,1))
title('Hossz')
figure(2)
plot(t,y(:,3))
title('Szög')
szog=@(ido)interp1(t,y(:,3),ido);
leeresido=fzero(szog,0.4)
hossz=interp1(t,y(:,1),leeresido)
leeresido =
0.44017
hossz =
0.61646
3. feladat
f=@(t)exp(-t.^2/2)/sqrt(2*pi);
fprintf(' x G(x)\n')
for x=0.1:0.1:3
fprintf(' %3.1f %8.7f\n',x,quad(f,0,x));
end
x G(x)
0.1 0.0398278
0.2 0.0792597
0.3 0.1179114
0.4 0.1554217
0.5 0.1914625
0.6 0.2257469
0.7 0.2580363
0.8 0.2881446
0.9 0.3159399
1.0 0.3413447
1.1 0.3643339
1.2 0.3849303
1.3 0.4031995
1.4 0.4192434
1.5 0.4331929
1.6 0.4452008
1.7 0.4554345
1.8 0.4640697
1.9 0.4712834
2.0 0.4772499
2.1 0.4821356
2.2 0.4860966
2.3 0.4892759
2.4 0.4918025
2.5 0.4937904
2.6 0.4953388
2.7 0.4965329
2.8 0.4974448
2.9 0.4981341
3.0 0.4986500
4. feladat
f=@(x)x.*(x-1).*exp(x);
ezplot(f,[0,1])
h=0.1;
x=0:h:1;
y=f(x);
int=h*(y(1)/2+y(end)/2+sum(y(2:end-1)))
quad(f,0,1)
z=polyfit(x,y,10);
zint=polyint(z);
polyval(zint,1)-polyval(zint,0)
int =
-0.27862
ans =
-0.28172
ans =
-0.28172
5. feladat
f=@(x)sin(x).^2.*(x.^3-x.^2+3*x)-5;
ezplot(f,[0,6])
x=3.8
h=0.0001;
if f(x)*(f(x-h)-2*f(x)+f(x+h))>0
der=(f(x+h)-f(x-h))/2/h;
for i=1:20
x=x-f(x)/der
end
else
disp('Nem tudunk semmit sem garantálni.')
end
x =
3.8
x =
3.5772
x =
3.5342
x =
3.5159
x =
3.5071
x =
3.5027
x =
3.5005
x =
3.4993
x =
3.4987
x =
3.4984
x =
3.4982
x =
3.4981
x =
3.4981
x =
3.4981
x =
3.4981
x =
3.4981
x =
3.4981
x =
3.4981
x =
3.498
x =
3.498
x =
3.498
6. feladat