miércoles, 18 de enero de 2012

Euler explícito en Matlab


clear all;close all;clc
fun=input('Ingresa la función f(t,y) entre comillas: ');
f=inline(fun,'t','y');
y(1)=input('Ingrese la condición inicial y(0): ');
t0=input('Ingrese t0: ');
max=input('Ingrese el t máximo: ');
h=input('Ingrese el paso: ');
t=t0:h:max;
n=length(t);


for i=1:n-1
    y(i+1)=y(i)+h*feval(f,t(i),y(i));
end


plot(t,y)

1 comentario: