practica 3 tello tapia
DESCRIPTION
metodos numericosTRANSCRIPT
Problema 3:
prob3.m
function [z]=prob3(f,df,a,b,y,h)x=a:h:b;n=length(x);z=[x(1) y];for i=1:n-1y=y+h*feval(f,x(i),y)+(h^2)/2*feval(df,x(i),y);z=[z ;x(i+1) y];end
Evaluando:
>> f=inline('(x.*x-1).*y');df=inline('((2*x+(x*x-1).^2).*y)');z=prob3(f,df,0,1,1,0.25)
z = 0 1.0000 0.2500 0.7813 0.5000 0.6318 0.7500 0.5442 1.0000 0.5134
Problema 4:
a) Con Euler:
Prob4.m
function [z]=prob4(f,a,b,y,h)x=a:h:b;n=length(x);z=[x(1) y];for i=1:n-1y=y+h*feval(f,x(i),y);z=[z ;x(i+1) y];end
Probando:
f=inline('4*exp(0.8*x)-0.5*y');z=prob4(f,0,3,2,0.1)
b) Con RK-2:
rk2.m
function [z]=rk2(f,a,b,y,h)x=a:h:b;n=length(x);z=[x(1) y];for i=1:n-1k1=h*feval(f,x(i),y(i));k2=f*feval(f,x(i+1),y(i)+k1);y(i+1)=y(i)+0.5*(k1+k2);z=[z ;x(i+1) y(i)];end
Probando
f=inline('4*exp(0.8*x)-0.5*y');
z=eulerp(f,0,3,2,0.1)
Z= 0 2.0000 0.1000 2.3000 0.2000 2.6183 0.3000 2.9568 0.4000 3.3175 0.5000 3.7024 0.6000 4.1140 0.7000 4.5548 0.8000 5.0273 0.9000 5.5345 1.0000 6.0796 1.1000 6.6658 1.2000 7.2969 1.3000 7.9767 1.4000 8.7096 1.5000 9.5000 1.6000 10.3531 1.7000 11.2741 1.8000 12.2689 1.9000 13.3437 2.0000 14.5054 2.1000 15.7613 2.2000 17.1195 2.3000 18.5885 2.4000 20.1777 2.5000 21.8972 2.6000 23.7579 2.7000 25.7718 2.8000 27.9517 2.9000 30.3114 3.0000 32.8661