Can you plot level curves in Mupad?

2 visualizzazioni (ultimi 30 giorni)
Billy
Billy il 20 Mag 2012
If you have a vector field in MATLAB, you can easily plot the level curves via `contour` and the vector field via `quiver`.
But in mupad, the command to plot the vector field is plot::VectorField2d http://www.mathworks.com/help/toolbox/mupad/plot/PRIMITIV_VectorField2d.html, but I cannot find any way to plot the contour lines of a vector-valued function in mupad

Risposta accettata

Billy
Billy il 20 Mag 2012
Yes, but you must use Implicit2d.
For example, say you have the function of 2 variables
f := (x,y)->x^2 + 4*y^2
The level curves are just where the function has a certain solution, say f(x,y) = 20.
plot( plot::Implicit2d( f(x,y)=20, x=-5..5, y=-5..5 ) )
Now the "level curves" just super-impose plots of f(x,y)=0, f(x,y)=10, f(x,y)=20.. etc on the same plot.
To get a contour plot in mupad, do this:
plot( plot::Implicit2d( f(x,y)=10*Z, x=-5..5, y=-5..5 ) $ Z=0..5 )
Unfortunately plot::Implicit2d can be quite slow, so this plot actually takes a long time to generate, even on a fast PC.
If you want to color-code the values, this is easy:
let's define
f2 := (x,y) -> x*exp(y) + cos( x*y )
Then run
plot( plot::Implicit2d( f2(x,y)=Z, x=-5..5, y=-5..5, Color=[-Z/10,Z/10,0] ) $ Z=-10..10 )
(When a color is given a negative value, it is rounded up to 0 actually).
Here negative values appear red, positive curves appear green.
This is exactly identical to using the "Contours" command of plot::Implicit2d, which would look like this:
plot( plot::Implicit2d( f2(x,y), x=-5..5, y=-5..5, Contours=[$-10..10] ) )

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by