Octave/Matlab: Difference between e^(-1*z) and exp(-1*z)

vicase98 picture vicase98 · Mar 4, 2018 · Viewed 13.3k times · Source

I am new with Octave and I have a problem.I thought the following codes were the same, but they produces different results. What is the difference? Thanks

Octave/Matlab: Difference between e^(-1*z) and exp(-1*z)

g = 1./(1 + e^(-1*z));

g = 1./(1 + exp(-1*z));

Where z is a vector, element or matrix

Answer

Sardar Usama picture Sardar Usama · Mar 4, 2018

In Octave

exp(1) equals e where e is Euler's number.

There are 4 operations/functions that are to be noted here:

e^x is same as expm(x) and e.^(x) is same as exp(x).

  • e^x and expm(m) represent e raise to the matrix x.
  • e.^(x) and exp(x) represent exponential ex for each element in matrix x.

If x is a scalar then all (e^x, expm(x), e.^x and exp(x)) are mathematically equal.
For your case, z is a matrix and hence you get different results.


In MATLAB,

e is not defined in MATLAB. exp(x) and expm(x) have same definitions in MATLAB as those that are described for Octave above.


PS: e or E are also used for E-notation in both MATLAB and Octave but that's a different thing.