Reputation: 1049
I'm trying to plotting a function but I receive an error and since I'm a newbie I don't know how to fix it.
f=-10:0.001:10;
>> w=1/sqrt(4+(2*pi*f)^2);
??? Error using ==> mpower
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.
where is the mistake?
Upvotes: 0
Views: 4354
Reputation: 12486
^
is the matrix power operator, mpower
. The syntax A^n
attempts to raise the (square) matrix A
to the n
th power. This will obviously fail if A
is not a square matrix (in your example, it is a vector).
Since your username includes eng
and you're posting about MATLAB, I assume that you are an engineering student - your introductory math course should have covered matrix math, and why A * A
is only defined for square A
.
You actually want the scalar operator .^
, as in A.^n
. This raises each element of A
to the n
th power.
Upvotes: 2
Reputation: 78364
The mistake is exactly where the error message says you have a mistake. Since you are a newbie at Matlab, and I am vicious, I think that it will be useful to your learning to figure this one out for yourself. Read the last line of the error message carefully.
Upvotes: 0