Is it possible that ode23 or ode45 could result in complex numbers instead of real ones? If Yes, what are the possible reasons for getting complex numbers once you would expect real ones?

조회 수: 23 (최근 30일)
Hi, I perfromed ode23 for solving a differential equation, but after some timesteps I started to get complex numbers (i.e. the imaginary part) as result, instead of real numbers. Based on my equations/calculations, I should always get real numbers, and I do not understand if/why those solvers could give imaginary numbers.
Therefore, Is it possible that ode23 or ode45 could result in complex numbers instead of real ones?
If Yes, what are the possible reasons for getting complex numbers once you would expect real ones?
More info on the ODE here:
Thanks a lot!
  댓글 수: 13
John D'Errico
John D'Errico 2020년 7월 7일
Sometimes when we don't know what the answer is, a group of people end up just making comments. Along the way, sometimes we might end up helping you, finding a solution as if by committee. If that worked, then great, you have a solution, and all is good in the world. What matters in the end is you have a solution to the problem.
Just watch out for those multiplying socks and hangars. :)
Sim
Sim 2020년 7월 10일
Thanks a lot to you all :)
@Steven Lord, thanks for your suggestion :) However, I do not see a so much difference by using the NonNegative option...
@John D'Errico, Yes you all gave me the right advices, thanks a lot :)
I think I partially fixed the issue of complex numbers by putting an abs() function here (please see my previous comment to @dpb, about the Qcell{i})
% c1, c2, c3 are constant numbers and h is the unknown quantity of the differential equation
A = abs((c1 * h)) / (c2 + h);
B = sqrt(c3 * A);
Qcell{i} = B * h;
However, once I run the code - and by using ode15s instead of the previous ode23t, since a bit faster than ode23t - I get this plot, which represents my unknown quantity "h" versus time "t", for different parts of my network:
At the beginnning, up to about t=13, everything looks correct to me, i.e. positive smooth curves (curve = equation's solutions).. However, after that time, some curves go negative and some get a spike..... Why?! :)
(Please let me know if I should open a new thread about this last question)

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

답변 (0개)

카테고리

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