0

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?

0

2 Answers 2

2

^ 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.

Sign up to request clarification or add additional context in comments.

4 Comments

also by w you probably mean angular frequency omega. Just because \omega looks like a w doesn't mean you should name it that way. ;)
Well I tried as you suggested me but I receive this error: Matrix dimensions must agree.
Same kind of mistake. Consider, for example, f = -10:1:10; g = 1 / f. Please read the documentation for arithmetic operators. First one was free, but you get to figure the second one out yourself. ;)
In general, always use the dotted version of a math operator unless you actually mean to do matrix math.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.