필터 지우기
필터 지우기

runge kutta method wont plot graph

조회 수: 2 (최근 30일)
jono93
jono93 2016년 3월 22일
답변: Stalin Samuel 2016년 3월 23일
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)

답변 (1개)

Stalin Samuel
Stalin Samuel 2016년 3월 23일
here you can find the example code

Community Treasure Hunt

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

Start Hunting!

Translated by