Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: solving via runge-kutta fourth order equation

$
0
0
i found some nice code at matlab that can be used however i cant make it run wth my odes.

if you can help me would be great.

so i define a function:

function dxdt = dlogq1(x,P,c1,c2,c3)

%x = log(Q);
g = c1+c2*x+c3*x^2; % ln(g(Q))= c1+c2*ln(Q)+c3*ln((Q))^2

dxdt = g*((P/exp(x))-1); % d(ln(Q))/dt=g(Q)*(P/Q-1) ;
end

main program:

h=1; % step size

c1=-3.87;
c2=1.64;
c3=-0.16;

P=-0.002666;
dt=1;
t = 0:h:3; % Calculates upto x(3)

x(1) = log(0.0505); % initial condition
t = zeros(1,length(t));

for i=1:(length(t)-1) % calculation loop
    k_1 = dlogq1(t(i),x(i));
    k_2 = dlogq1(t(i)+0.5*h,x(i)+0.5*h*k_1);
    k_3 = dlogq1((t(i)+0.5*h),(x(i)+0.5*h*k_2));
    k_4 = dlogq1((t(i)+h),(x(i)+k_3*h));

    x(i+1) = x(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h; % main equation
end


i have problems with certain input parameters ...

thanks

Viewing all articles
Browse latest Browse all 19628

Trending Articles