Borrar filtros
Borrar filtros

runge kutta method wont plot graph

2 visualizaciones (últimos 30 días)
jono93
jono93 el 22 de Mzo. de 2016
Respondida: Stalin Samuel el 23 de Mzo. de 2016
hi all i am having some issues plotting a runge kutta method ode. the general ode is
da/dz=0.5beta2*x1*x4 where the initial conditions of x1 and x4 are 0.23 and 0.0079 respectivily and beta2 has a value of 17 this is the code i have done so far
close all
%define constants
%equation to plot is dx1/dz =0.5*beta2*x1*x4
%initial conditions are x1=0.23 and x4=-0.0079
%time=1.422*10^-15;
%w=1/time;
%n2=2.7*10^-20;
%Aeff=80*10^-6;
%c=340;
beta2=17*10^-6;
%a=x1,b=x4
%defines function
f=@(a,b)0.5*beta2*a*b;
%initial conditions taken from paper
a(1)=0.23;
b(1)=-0.0079;
%stepsize
h=0.5;
z=linspace(0,1000,1000);
N=ceil(z/h);
for i=1:N
k1=f(a(i), b(i))
k2=f(0.5*h,a(i)+0.5*k1,b(i)+0.5*k1)
k3=f(0.5*h,a(i)+0.5*k2), b(i)+0.5*k2
k4=f(0.5*h,a(i)+0.5*k3, b(i)+0.5*k3)
y(i+1)=(1/6)*k1+(1/3)*k2+(1/3)*k3+(1/6)*k4
end
plot(z,a)

Respuestas (1)

Stalin Samuel
Stalin Samuel el 23 de Mzo. de 2016
here you can find the example code

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by