fminsearch returns complex numbers as a result

8 次查看(过去 30 天)
Hello,
I have system of ODE, which I've optimised using fminsearch. Unfortunately, the return number while used to obtain the numerical solution returns solution with imaginary part equal to zero. This is a problem as I want to use MatCont to do bifurcation. Is there a way to make sure that found parameters will return only real values? I've tried using command:
if any(~isreal(dxdt))
keyboard
end.
Unfortunately, while incorporating these few lines into my ODE function I'm getting only lines as the solution. Parameters which I've found with fminsearch produce harmonic behaviour of the solutions as expected. Is there any lines of code which I can add or other solver, which would fix this problem?
Thank you in advance.
  3 个评论
Malgorzata Wieteska
Hello Torsten, Thank you for your answer. I've tried to use: options1 = odeset('Refine',13); options2 = odeset(options1,'NonNegative',13); Unfortunately, I'm getting error: Error using odeset (line 216); Unrecognized property name 'NonNegative'. Ia ny way to overcome this?
Torsten
Torsten 2021-5-28
You write that the returned solution has imaginary part, but it is equal to zero. Then why not convert the imaginary number into real by transferring only the real part to MatCont ?

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2021-5-28
If you are sure, that only the real part of the result matters, what about cropping the imaginary part?
finalY = real(y(end, :))
  3 个评论
Jan
Jan 2021-5-28
So maybe your code contains a typo which causes the imaginary solution. Matlab does not do this without a reason. So insert a check in your code and let the debugger stop to examine, what's going on:
function dy = YourFcn(t, y)
...
if ~isreal(dy)
disp('imaginary value') % <-- set a breakpoint here
end
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by