Reputation: 33
I've been searching the web for the past hours trying to find some way to implement a routine/function in Mathematica that basically does your plotting. I've written code that only needs a two dimensional field, say:
dx/dt = x-x^2
dy/dt = y-y^2.
What I do from here on is that I solve for the fix points and then numerically integrate a few trajectories and plot them together...
Now the question is can I somehow compose my code into a function like in Matlab? I've been researching the concepts of Module, and Block but it seems to be impossible for me to return the plot.
So for clarification I want to be able to write a function that takes as an argument only the field, and then returns a plot of the field to me ( with customised trajectories from the fix points etc..
CustomPlotField[dxdt,dydt] := ............
Since I do a lot of stuff for the plotting, the code is pretty large so i copy pasting chunks of code for plots that I'm doing regularly feels a bit annoying.
Thanks in advance!
Upvotes: 1
Views: 127
Reputation: 31145
As far as I can tell, you are on the right track looking at modules:
https://reference.wolfram.com/language/tutorial/ModulesAndLocalVariables.html
To return the plot just evaluate it as the last expression in the body of the Module. Or use an explit Return.
http://reference.wolfram.com/language/ref/Return.html
Upvotes: 0