Am I writing this exponential function the right way?
2 views (last 30 days)
Show older comments
I just got into MATLAB and trying different things, right now I'm experimenting with 3D plots. I'm not sure if I'm writing this exponential function the right way. 

My input looks following: z=x*exp((-x^2-y^2)); I'm not sure if I'm getting the right output with mesh(x,y,z), it looks different from what I expeted :) 

Answers (1)
John D'Errico
on 15 Nov 2022
Edited: John D'Errico
on 15 Nov 2022
You need to learn about the dotted operators. They are used when you will be performing ELEMENT-wise squaring, multiplications, and powers.
z=x.*exp((-x.^2-y.^2));
There are no dotted adds or subtracts. But the regular * / and ^ operators do something different when you have matrices. The two sets of operators are the same for scalars, so when you first learned MATLAB, you saw no problems. But matrices (and vectors) are different animals.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!