MATLAB: What is the difference between using a “.” in mathematical operations
mathematicsoperators
For example, x.^2 and x^2.
Thank you!
Best Answer
if x is a vector/ matrix , you have to use x.^2. It is element by element power. If x is a scalar, x^2 is sufficient. Read about element by element operations in matlab.
You probably need to use theelement-wise power, just like the error message tells you:
>> x = 1:4;
>> diff(1/2*sqrt(2*pi.^exp(-1*x).^2))
ans =
-0.251803 -0.077017 -0.026488
But this depends onwhat the formula is supposed to do, which you do not tell us. In any case you should learn about the differences betweenmatrix andelement-wise operations:
Best Answer