# Problem with ploting exp function

3 visualizzazioni (ultimi 30 giorni)
Dinh Le Dung il 2 Mag 2022
Commentato: Dinh Le Dung il 3 Mag 2022
I try to plot t(x,y) = (x^2 - 2y^2)*e^(x-y) in Matlab and i use the following code
t=@(x,y)((x.^2-2*y.^2).*exp(x-y));
x = -1:2/50:1;
y = -2:4/50:2;
[X, Y] = meshgrid(x, y);
surf(X, Y, t(X,Y));
rotate3d on;
I got the result but it is not the same as i drawn in Geogebra
I think there is a problem with .*exp(x-y)
##### 4 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Walter Roberson il 3 Mag 2022
Very different plotting ranges.
Dinh Le Dung il 3 Mag 2022
I see, thanks for your help sir!

Accedi per commentare.

### Risposta accettata

Stephen23 il 3 Mag 2022
Modificato: Stephen23 il 3 Mag 2022
"I think there is a problem with .*exp(x-y)"
I doubt that. Did you look at the domains and ranges that you are plotting?
Your Geogebra example shows that you plotted over x = -8..+8 and y = -8..+8. Then in MATLAB you plotted over x = -1..1 and y = -2..2. And then you did not limit the Z axes to the same range as your example plot. Lets try that now:
x = -8:0.5:8;
y = -8:0.5:8;
[X,Y] = meshgrid(x,y);
T = (X.^2-2*Y.^2).*exp(X-Y);
surf(X,Y,T);
zlim([-3,6])
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Più risposte (1)

Catalytic il 2 Mag 2022
If I had to guess, you have x and y reversed.
[X, Y] = ndgrid(x, y);
surf(X, Y, t(X,Y));
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Dinh Le Dung il 3 Mag 2022
i dont think so :((, but thanks for your help!

Accedi per commentare.

### Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by