Plotting 3D functions
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Spaceman
am 19 Mär. 2024
Kommentiert: Spaceman
am 8 Apr. 2024
Given: Create both a contour and surface plot for the following function.
Find:
- Create an x vector between -2 and 2, with a step size of .2
- Create a y vector between -2 and 2, with a step size of .2
- Create a matrix X and Y that contains a grid of coordinate pairs from x and y
- Create a matrix Z that is the same size as X and Y
Create the following plots, with labels
- Contour plot
- Surface plot
Issue: I have what I believe to be the correct code, however, it's giving me an error stating not enough input arguments...
My Solution: What am I missing here?
x=-2:0.2:2
y=x
[X,Y]=meshgrid(x,y)
Z=x.*exp.^-(x.^2+y.^2)
contour(X,Y,Z)
surf(X,Y,Z)
0 Kommentare
Akzeptierte Antwort
the cyclist
am 19 Mär. 2024
Bearbeitet: the cyclist
am 19 Mär. 2024
You used exp as if it were a constant (e) that is raised to a power. Instead, you should have used it as a function.
You also used x and y instead of X and Y, when calculating Z.
x=-2:0.2:2;
y=x;
[X,Y]=meshgrid(x,y);
Z=X.*exp(-(X.^2+Y.^2));
figure
contour(X,Y,Z)
figure
surf(X,Y,Z)
3 Kommentare
the cyclist
am 21 Mär. 2024
If you don't use parentheses, you are relying on the defined operator precedence. Sometimes, parentheses are better, just for clarity.
Semicolons suppress command window output, not all output. A semicolon such as
surf(X,Y,Z);
is superfluous.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!