Qué devuelve ODE45??
Publicado por Adriel (2 intervenciones) el 17/11/2011 15:38:49
Puede ser la diferencia tan grande entre RungeKutta y ODE45 en los grafos?
close all
clear all
clc, clf,
U=240;
tslut=0.01;
Lo=1;
C=1e-6;
%ODE45 med Reltol
du = @(t,u)[ u(2); (2*u(1)/(1+u(1)^2))*u(2)^2-(1+u(1)^2)*u(1)/(Lo*C) ];
opt = odeset('Reltol', 1e-3);
[t,u] = ode45(du, [0 tslut], [0 U/Lo], opt);
grid on
plot(t,u(:,1),'--'), hold all
format long
%disp([t,u(:,1)])
%Runge-Kutta
t=0; y=[0 U/Lo]; T=t; Y=y; h=0.0001;
dy = @(t,y)[ y(2) (2*y(1)/(1+y(1)^2))*y(2)^2-(1+y(1)^2)*y(1)/(Lo*C) ];
while t < tslut-h/2;
f1= dy(t,y);
f2= dy(t+h/2, y+h*f1/2);
f3= dy(t+h/2, y+h*f2/2);
f4= dy(t+h, y+h*f3);
y=y+h/6*(f1+f2+f3+f4); t=t+h; T=[T;t]; Y=[Y;y];
end
plot(T,Y(:,1))
close all
clear all
clc, clf,
U=240;
tslut=0.01;
Lo=1;
C=1e-6;
%ODE45 med Reltol
du = @(t,u)[ u(2); (2*u(1)/(1+u(1)^2))*u(2)^2-(1+u(1)^2)*u(1)/(Lo*C) ];
opt = odeset('Reltol', 1e-3);
[t,u] = ode45(du, [0 tslut], [0 U/Lo], opt);
grid on
plot(t,u(:,1),'--'), hold all
format long
%disp([t,u(:,1)])
%Runge-Kutta
t=0; y=[0 U/Lo]; T=t; Y=y; h=0.0001;
dy = @(t,y)[ y(2) (2*y(1)/(1+y(1)^2))*y(2)^2-(1+y(1)^2)*y(1)/(Lo*C) ];
while t < tslut-h/2;
f1= dy(t,y);
f2= dy(t+h/2, y+h*f1/2);
f3= dy(t+h/2, y+h*f2/2);
f4= dy(t+h, y+h*f3);
y=y+h/6*(f1+f2+f3+f4); t=t+h; T=[T;t]; Y=[Y;y];
end
plot(T,Y(:,1))
Valora esta pregunta


0