Phase portrait for Complex ODE

Hi, I am trying to use:
if true
% code
end
function pdecaller()
options = odeset('OutputFcn',@odephas2);
for i=-4:4
for j= -4:4
[t,y] = ode45(@vdp1,[0 20],[i;j],options); hold on;
end
end
end
%c
function dydt = vdp1(t,y)
dydt=[ -i*(5.34E-12.*2.*2.033E-22)/((3.66E-5)^2).*y(1)-5.79E-68; y(2)];;
end
to plot a complex phase portrait. It gives however the result:
>> phaseportrait_caller Error using odephas2 (line 67) Error updating the ODEPHAS2 window. Solution data may have been corrupted. Argument X cannot be complex.
Error in ode45 (line 435) stop = feval(outputFcn,tout_new,yout_new(outputs,:),'',outputArgs{:});
Error in phaseportrait_caller (line 5) [t,y] = ode45(@vdp1,[0 20],[i;j],options); hold on;
Can anyone think of an alternative?
Thanks

2 Comments

What is the purpose of "hold on" here? It seems like the error occurs in odepahs2, but you did not post the corresponding code.
Your initial values have the magnitude of 1. The formula for the 1st component is (constants calculated already):
1i * 1.6208635671414494e-33 * y(1) - 5.79e-68
and the 2nd component is fixed. Then the 2nd component is independent from the 1st one and you can omit the repeated integrations. Note that the term "5.79e-68" will matter for i=0 only, because it is too tiny and the limited precision will round it away.
I'm not sure if the step size control of ODE45 handles the two magnitudes differing by a factor of 1e32 as you expect it. Maybe it is smarter to scale the inputs to be in the same magnitude.
Sergio Manzetti
Sergio Manzetti on 23 Nov 2017
Edited: Sergio Manzetti on 23 Nov 2017
I don't know if this is related to your point Jan, but this software plots linear flow of vectors when it should plot a spiral flow phase portrait.

Sign in to comment.

 Accepted Answer

Birdman
Birdman on 23 Nov 2017
Run the attached m file in command line and a GUI will open. Then enter your differential equations and you can easily plot the phase portrait for your ode.

15 Comments

Thanks for this. I tried to run it and got:
Undefined function or variable 'pplane8'.
Error in phase_portrait (line 401) pplane8('figdefault',ppset);
Another try gives a GUI that asks to "Close Those figures" or restart pplane8. In either case, it doesn't start.
Are you sure that you saved it to your current directory? Because my computer opens it and it has a GUI like in attached figure.
I saved it in the script directory I have all other MATLAB files. Should it be in a specific folder?
No, it is at right place actually. But try the following then:
Please delete the previous one before putting this into your directory.
Sergio Manzetti
Sergio Manzetti on 23 Nov 2017
Edited: Sergio Manzetti on 23 Nov 2017
It worked!
How can the scale of the plot be increased?
Can the plot be closed without having to restart the program?
Birdman
Birdman on 23 Nov 2017
Edited: Birdman on 23 Nov 2017
I assume it can be done by changing the minimum and maximum values of x and y respectively under the The display window sentence.
Edit: you don't have to close the plot. Just write another diff eq and click on Proceed again. It will automatically plot the phase portrait.
Something is strange, the figure shows what the Plot plots, while the program shows the equation WITH x variable in the second ODE. Is this a small graphical bug, or is it a misinterpretation between the two interfaces?
Jan
Jan on 23 Nov 2017
Edited: Jan on 23 Nov 2017
@cvklpstunc: Your code mentions the author
% Hugh Harvey, George Williams, University of Bristol
% Last Modified: February 6, 2016
But maybe the code is copyrighted by:
% Copywright (c) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003
% John C. Polking, Rice University
Publishing foreign code under the CC BY-SA 3.0 license by posting it in the froum is not necessarily okay.
The code adds the tempdir folder on top of the Matlab path. This is a really bad idea, because this folder might contain M-functions, which might shadow built-in functions. The code uses strings as callbacks - this is still working for backward compatibility, but outdated for over 15 years now. You find a lot of eval commands inside.
This is not your problem, because you did not write the code. But I wanted to mention the poor code quality to warn Sergio.
@Jan: This code is public open, you can find it on the internet.
@Sergio: make sure you enter your differential equation correctly.
Cvl, thanks I have now. I have tried to set a color on the arrows by position in the graph, is that possible? Thus, the arrows further away with high x values have yellow color, while low values have dark color, or similar.
I have never tried it, so I can not say anything.
Thanks, this was an excellent program.
Jan
Jan on 23 Nov 2017
Edited: Jan on 23 Nov 2017
@cvklpstunc: Finding a file in the internet, does not mean, that it is "public open" and that you can use it how ever you want. Especially when it is coming from the FileExchange, it is covered by the BSD license. You find the license file on the FileExchange page and in the downloaded ZIP file. Publishing the code without the license file is not allowed. Posting it in the forum means to publish it under CC BY-SA 3.0, which is not exactly the same as the BSD.
It is much more useful to post the link to FileExchange instead of the code: Then the readers in the forum get the current version of the code in a few years also and there is not trouble with the license at all.
@Jan: ok, i will be careful next time about it, thanks.

Sign in to comment.

More Answers (1)

Sergio Manzetti
Sergio Manzetti on 23 Nov 2017
thanks! I can only see arrows pointing in one direction

1 Comment

If the answer is useful, please accept it. And delete this answer. If you want to reply, write it under my answer.

Sign in to comment.

Categories

Asked:

on 23 Nov 2017

Edited:

Jan
on 23 Nov 2017

Community Treasure Hunt

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

Start Hunting!