How to represent e^(-t^2) in MATLAB?

user573382 picture user573382 · Mar 6, 2011 · Viewed 162.4k times · Source

I am a beginner in MATLAB, and I need to represent e(-t2).

I know that, for example, to represent ex I use exp(x), and I have tried the following

1) tp=t^2; / tp=t*t; x=exp(-tp);

2) x=exp(-t^2);

3) x=exp(-(t*t));

4) x=exp(-t)*exp(-t);

What is the correct way to do it?

Answer

Tim picture Tim · Mar 6, 2011

If t is a matrix, you need to use the element-wise multiplication or exponentiation. Note the dot.

x = exp( -t.^2 )

or

x = exp( -t.*t )