How to solve runge kutta using implicit method

6 visualizzazioni (ultimi 30 giorni)
Rong
Rong il 30 Mag 2014
Commentato: Sara il 31 Mag 2014
hey guys I am trying to write a script using runge kutta implicit method 4th order I got the following equations
for n =2:(N-1)
k_1 = f(tout(n-1) +(0.5+(sqrt(3)/6)*h) , yout(:,n-1) + 0.25*h*k_1 + (0.25 + (sqrt(3)/6))*h * k_2);
k_2 = f(tout(n-1) +(0.5-(sqrt(3)/6)*h) , yout(:,n-1) + (0.25-(sqrt(3)/6))*h*k_1 + 0.25*h * k_2);
yout(:,n) = yout(:,n-1) + (h/2)*(k_1 + k_2);
end
but to find k_1, I need a value for k_1 and to find k_2 I need a value for k_2
how I am supposed to do it? Didn't undestrand implict method...

Risposte (2)

Sara
Sara il 30 Mag 2014
Implicit means the equation has no analytic solution, i.e. you'll have to solve it iteratively. Meaning, you try guessing the value of your unknown, plug it into your equation and see if the right side is equal to the left side. In your case, for each iteration, you'll have to solve a system of algebraic equations. You can use fsolve for that, just rewrite your equations in k_1 and k_2 in the form f = (right side)-(left side)
  1 Commento
Rong
Rong il 31 Mag 2014
Hi, thank you I tried to implement fsolve inside the loop and it didnt work do I need to create another script just to define these equations?

Accedi per commentare.


Rong
Rong il 31 Mag 2014
I did this
for n =2:(N-1) % calculation loop
fun = @(k) [k(1) - (f(tout(n-1) +(0.5+(sqrt(3)/6)*h) , yout(:,n-1) + 0.25*h*k(1) + (0.25 + (sqrt(3)/6))*h * k(2)));
k(2) - f(tout(n-1) +(0.5-(sqrt(3)/6)*h) , yout(:,n-1) + (0.25-(sqrt(3)/6))*h*k(1) + 0.25*h * k(2))];
fsolve(fun, [h;h]);
yout(:,n) = yout(:,n-1) + (h/2)*(k(1) + k(2)); % main equation
end
and it says that
IRK4
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using
Levenberg-Marquardt algorithm instead.
> In fsolve at 314
In IRK4Solver at 25
In main at 38
No solution found.
fsolve stopped because the last step was ineffective. However, the vector of function
values is not near zero, as measured by the default value of the function tolerance.
  1 Commento
Sara
Sara il 31 Mag 2014
What is the function f that you are trying to integrate? Can you attach all your code, input values included?

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by