MATLAB: Error using ^ One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power.

graphingMATLABquestion

a1= input('Enter Value in Kohms for R = ');
a2= input('Enter Value in Micro Farads for C = ');
R= a1*1000;
C= a2*10^-6;
FC= 1/(2*3.14*R*C);
x = 10 : 100 : 1000000;
yx = 1/(sqrt(1+(x/FC)^.2));
plot(x,yx)
end
I tried to use this code in order to graph a high pass circuit, but im getting an error. (One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power.)
One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power.
Error in untitled2 (line 10)
yx = 1/(sqrt(1+(x/FC)^2));

Best Answer

Consider the matrix
A = [1 2;3 4];
Suppose you wanted to multiply the matrix with itself?
B = A*A;
Essentially, we have squared the matrix, raised it to a power. So we could also write
B=A^2;
Is this the same thing as squaring each element of the matrix? NOOOOOO! A matrix multiplication is NOT the same thing.
If all we want to do is square the individual elements of a matrix, or to multiply two matrices, element by element, then we use the dotted operators, thus .* ./ and .^
A = [1 2;3 4]
A =
1 2
3 4
A^2
ans =
7 10
15 22
A*A
ans =
7 10
15 22
A.^2
ans =
1 4
9 16
A.*A
ans =
1 4
9 16
Division also needs an element-wise operator.
A = A./A
A =
1 1
1 1
That makes complete sense of course. See that this is very different from
A/A
Warning: Matrix is singular to working precision.
ans =
NaN NaN
NaN NaN
which fails, because the matrix A is indeed a singular matrix. / and \ are used to solve linear systems of equations.
Oh, by the way, there is no need to have element-wise versions of the + or - operators, so you need not worry there.
There is a difference between ^ and .^, as well as the other similar operators. Remember it, as it will be important in your code.