Plotting 2D contours syntax

4 views (last 30 days)
Tatte Berklee
Tatte Berklee on 31 Aug 2022
Commented: Tatte Berklee on 31 Aug 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!

Accepted Answer

Steven Lord
Steven Lord on 31 Aug 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 Comments
Tatte Berklee
Tatte Berklee on 31 Aug 2022
Thanks a lot, Steve! It helped a lot!

Sign in to comment.

More Answers (0)

Categories

Find more on Contour Plots in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by