Solving coupled ODE's by ode45

조회 수: 1 (최근 30일)
Niles Martinsen
Niles Martinsen 2012년 9월 11일
편집: Tomorrow 2017년 9월 10일
Hi
I have a relatively simple set of coupled ODE's that I am trying to solve by ODE45. The following is the content of the .m-file, which shows the coupled system:
function xprime = eoms(t, x)
xprime = [
1e9 + 5.0e4*x(3) - 50*x(1);
4.0e1*x(1) - 3.3e3*x(2);
2.0e3*x(2) - 5e4*x(3) + 3.5e7*heaviside(t-1)*x(4);
1.0e3*x(2) - heaviside(t-1)*5.0e7*x(4)];
I solve it using the following command:
x0 = [0 0 0 0];
tspan = [0, 2];
[t, x] = ode45(@eoms, tspan, x0);
However when I compile MatLAB just keeps calculating, it doesn't give me a result. I think it has something to due with the fact that the Heaviside step-function, because if I take it out then it nicely solves the remaining part. I have also tried in a competing software, and the same thing happens (actually, there the solver just gives an error).
Maybe it is also due to the very rapid rates in the equations. Anyhow, I am really lost on what to do - unfortunately I need the transient behavior, so I can't just assume steady-state for some of the equations.
Do I have any options here?
Thanks in advance.
Best, Niles.
  댓글 수: 1
MUFTAH AKROUSH
MUFTAH AKROUSH 2015년 12월 16일
Hi. I want to know How i can solve 4 differential equations like this v_dot(1)= 3*x(1)+v(2)-x(2)+v(3)-x(4)-x(5)+v(4); with 2 variables with Function command and ode45?

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2012년 9월 11일
편집: Star Strider 2012년 9월 11일
You have a ‘stiff’ system, and ode45 is not the best option for it, although it's an appropriate initial experiment. If ode45 seems not to work (and the system otherwise seems to be solvable in some situations as yours was), switching to ode15s is appropriate, especially in systems with coefficients of widely-ranging magniudes such as yours are (from 4E+1 to 1E+9).
After experiencing the same problem you did with ode45, I ran your code with ode15s and it solved your eoms system in 1.2225 seconds.
So I suggest you simply change your ODE function call to:
[t, x] = ode15s(@eoms, tspan, x0);
and enjoy the results!
Also, I coded your function as an implicit function to run it, avoiding the need to save a separate function m-file. (This isn't always possible, but it works in many situations.)
The function:
eoms = @(t,x) [1e9 + 5.0e4*x(3) - 50*x(1); 4.0e1*x(1) - 3.3e3*x(2); 2.0e3*x(2) - 5e4*x(3) + 3.5e7*heaviside(t-1)*x(4); 1.0e3*x(2) - heaviside(t-1)*5.0e7*x(4)];
and the call to it changes to:
[t, x] = ode15s(eoms, tspan, x0);
  댓글 수: 3
Star Strider
Star Strider 2012년 9월 13일
As always, it is my pleasure to help!
Tomorrow
Tomorrow 2017년 9월 10일
편집: Tomorrow 2017년 9월 10일
could you help me with this stiff ODEs ? thanks so much * _ error in ode solver for heaviside function _*

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Shashank
Shashank 2013년 6월 28일
Star Strider, could you please help me solve this set of four coupled ODEs?
tpcl = @(xi,y) [y(2); ((1 + (y(2)*y(2)))^(1.5))*(y(3) - (A/(y(1)^3)))/sigma; -3*mu_l*y(4)/(rho_l*h_lv*(y(1)^3)); (Twall - Tsat - (Tsat*y(3)/(rho_l*h_lv)))/((y(1)/k_l) + R_int)];
xi_step = 0:1e-8:xi_end;
[XI,Y] = ode15s(tpcl,xi_step,[delta_ad deltaprime_ad delta_p_ad Q_ad]);
Here, apart from the variables y(1), y(2), y(3) and y(4), everything is a constant. I tried ode45 and ode15 but it still did not work. The results look unrealistic to say the least.
  댓글 수: 1
Marc
Marc 2013년 6월 29일
You need to give us your constants. You may want to post this in the newsgroup, which is more for helping folks with there code snafus.

댓글을 달려면 로그인하십시오.


MUFTAH AKROUSH
MUFTAH AKROUSH 2015년 12월 16일
Hi. I want to know How i can solve 4 differential equations like this v_dot(1)= 3*x(1)+v(2)-x(2)+v(3)-x(4)-x(5)+v(4); with 2 variables with Function command and ode45?

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by