Torsten
Posts:
1,488
Registered:
11/8/10


Re: solving via rungekutta fourth order equation
Posted:
Jun 20, 2013 6:22 AM


"Alex" wrote in message <kpsk71$bj1$1@newscl01ah.mathworks.com>... > "Alex" wrote in message <kpsfh2$rcl$1@newscl01ah.mathworks.com>... > > "Steven_Lord" <slord@mathworks.com> wrote in message <kpsemn$p3m$1@newscl01ah.mathworks.com>... > > > > > > > > > "Alex " <damdamrgf@yahoo.com> wrote in message > > > news:kpsd49$km8$1@newscl01ah.mathworks.com... > > > > Hi there, > > > > > > > > I am quite new to matlab and have one question regarding solving odf using > > > > Rungekutta fourth order. > > > > > > > > I solved it in excel, however looking forward to implement it into matlab > > > > for better performance. > > > > > > > > so i have to solve this equation : > > > > > > > > d(ln(Q))/dt=g(Q)*(P/Q1) ; > > > > > > Let Y = log(Q). Thus: > > > > > > dY/dt = g(exp(Y))*(P/(exp(Y)1)) > > > > > > This is in the form expected by the ODE solvers included in MATLAB. Try > > > ODE45 first, and if that doesn't work because the problem is too stiff > > > switch to one of the stiffer solvers. The documentation includes a table > > > describing which solvers are stiff and which are nonstiff. > > > > > > > by solving via rungekutta it should looks like this: > > > > ln(Q) in step n+1= ln(Q) at step n + 1/6*h*(s1+2s2+ss3+s4) ; > > > > > > > > where Q, and P are know values let say: > > > > > > Wait, what? What EXACTLY are you trying to solve for if you already know Q > > > and P? You're already done, aren't you? > > > > > >  > > > Steve Lord > > > slord@mathworks.com > > > To contact Technical Support use the Contact Us link on > > > http://www.mathworks.com > > > > I have just first value of Q as an initial condition that should be used with rungekutta 4th order scheme. > > > > so ln(Q) in step n+1 (we are searchig for it) = ln(Q) at step n (the initial condition when n=1) + 1/6*h*(s1+2s2+ss3+s4) ; > > > i found some code tthat i could used in my computation. however i have still some problems with input parameters, if someone can help me that would be great. thanks!!! > > %so i defined a function as : > 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/Q1) ; > 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 > > thanks al.
If your function dlogq1 has parameter list function dxdt = dlogq1(x,P,c1,c2,c3), you will have to call it with this parameter list. Thus for i=1:(length(t)1) % calculation loop k_1 = dlogq1(t(i),x(i),c1,c2,c3); k_2 = dlogq1(t(i)+0.5*h,x(i)+0.5*h*k_1,c1,c2,c3); k_3 = dlogq1(t(i)+0.5*h,x(i)+0.5*h*k_2,c1,c2,c3); k_4 = dlogq1(t(i)+h,x(i)+k_3*h,c1,c2,c3); x(i+1) = x(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h; % main equation end
Best wishes Torsten.

