eng_mazzy
eng_mazzy

Reputation: 1049

error plotting function using matlab

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

Answers (2)

Li-aung Yip
Li-aung Yip

Reputation: 12486

^ is the matrix power operator, mpower. The syntax A^n attempts to raise the (square) matrix A to the nth 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 nth power.

Upvotes: 2

High Performance Mark
High Performance Mark

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

Related Questions