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

2

7

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?

Herdsman answered 6/3, 2011 at 12:43 Comment(2)
no. 4 (x=exp(-t)*exp(-t);) is mathematically wrong.Astonishing
exp(-t)*exp(-t) is NOT equivalent to exp(-t^2), it is equivalent to exp(-2*t), a rather different number.Stay
F
14

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 )
Fucoid answered 6/3, 2011 at 12:46 Comment(0)
A
5

All the 3 first ways are identical. You have make sure that if t is a matrix you add . before using multiplication or the power.

for matrix:

t= [1 2 3;2 3 4;3 4 5];
tp=t.*t;
x=exp(-(t.^2));
y=exp(-(t.*t));
z=exp(-(tp));

gives the results:

x =

0.3679    0.0183    0.0001
0.0183    0.0001    0.0000
0.0001    0.0000    0.0000

y =

0.3679    0.0183    0.0001
0.0183    0.0001    0.0000
0.0001    0.0000    0.0000

z=

0.3679    0.0183    0.0001
0.0183    0.0001    0.0000
0.0001    0.0000    0.0000

And using a scalar:

p=3;
pp=p^2;
x=exp(-(p^2));
y=exp(-(p*p));
z=exp(-pp);

gives the results:

x =

1.2341e-004

y =

1.2341e-004

z =

1.2341e-004
Astonishing answered 6/3, 2011 at 13:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.