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?

35 visualizaciones (últimos 30 días)
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 comentarios
John D'Errico
John D'Errico el 7 de Jul. de 2020
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 el 10 de Jul. de 2020
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)

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by