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

I am new to MATLAB and I need to introduce e (- t 2 ) .

I know that, for example, I use exp(x) to represent e x , and I 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 right way to do this?

+6
matlab exponential exp
source share
2 answers

If t is a matrix, you need to use multiplication or exponentiation by elements. Pay attention to the point.

 x = exp( -t.^2 ) 

or

 x = exp( -t.*t ) 
+14
source share

All three first methods are identical. Make sure that if t is a matrix, you add . before using multiplication or 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 
+5
source share

All Articles