Plotting 2D contours syntax

5 visualizaciones (últimos 30 días)
Tatte Berklee
Tatte Berklee el 31 de Ag. de 2022
Comentada: Tatte Berklee el 31 de Ag. de 2022
folks,
I have a few novice questions with plotting the following function:
My codes is:
zfun = @(x1,x2) x1./(x2.*(1-x1)-1);
zhandle = fcontour(zfun)
  1. Is this the correct way to plot the contour? I am mainly concenred with having the "dot" after the variable.
  2. Why do I get an error when I do this?
zfun = @(x1,x2) x1./(x2.*(1-x1.)-1);
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
zhandle = fcontour(zfun)
3. Is there a way to see how the contour changes, say fixing x2? For example, I would like to fix x2 to be say .5, and see how the contour plot changes with x1. Of course, this is just 1D plot, but is there a way to aggregate these graphs? is mesh the way to go?
Thanks in advance!

Respuesta aceptada

Steven Lord
Steven Lord el 31 de Ag. de 2022
I am mainly concenred with having the "dot" after the variable.
The dot is not associated with the variable, it's associated with the operator. Don't think "x1.", think "./" See this documentation page for more information about the differences between the array operator ./ and the matrix operator / in MATLAB.
Why do I get an error when I do this?
Because x1. is not valid in MATLAB unless the next character is an array operator. There are situations where a value can have a trailing dot without an operator, like defining a literal numeric value: using 1. is equivalent to just plain 1 or 1.0. All three values in x below are equal to one.
x = [1 , 1. , 1.0]
x = 1×3
1 1 1
Is there a way to see how the contour changes, say fixing x2?
So you just want a line plot?
zfun = @(x1,x2) x1./(x2.*(1-x1)-1);
fplot(@(x) zfun(x, 5))
title('x2 equal to 5')
  4 comentarios
Steven Lord
Steven Lord el 31 de Ag. de 2022
When I perform 1-x1, from each element in an array x1, I am performing 1 minust that element, correct?
Let's see.
A = magic(3)
A = 3×3
8 1 6 3 5 7 4 9 2
B = 1 - A
B = 3×3
-7 0 -5 -2 -4 -6 -3 -8 -1
Each element of B is 1 minus the corresponding element from A.
I want that kind of line plot but over lay for different values of x2. You did it with x2=5, but can I have an overlay for specific values like x2=1,2,3,4,5?
Sure. Just use hold on to put multiple lines on the same plot. You might want to add line styles or colors or set the DisplayName property of each line and then add a legend to your plot to make it easier to distinguish the plots.
zfun = @(x1,x2) x1./(x2.*(1-x1)-1);
for x2 = 1:5
fplot(@(x) zfun(x, x2), 'DisplayName', "x2 = " + x2)
hold on
end
legend show % Use the names for each line from its DisplayName
Tatte Berklee
Tatte Berklee el 31 de Ag. de 2022
Thanks a lot, Steve! It helped a lot!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by