This is a simple error of syntax, which seems a bit strange for someone who has written such a long code to misunderstand. You should spend a little time learning the basic syntax of MATLAB.
MATLAB uses * to multiply. Or .* if you want to make sure that this is an element-wise matiplication. But it uses an operator to multiply.
The point is though, that
(x-y)(x+y)
is NOT the product of those two numbers, at least not in MATLAB. It may be that when you write it on paper, etc. But in MATLAB? What I wrote there is a syntax error. If you want to multiply numbers, then you genrally need to write
(x-y).*(x+y)
in case they are vectors or matrices. If both x and y are scalars, then it would be sufficient to write:
(x-y)*(x+y)
But in any case, you can see that I put an operator in there, between the pieces. Now go back and read the error message. Look at the point that is indicated. MATLAB sees a situation just like what I wrote, and it does not understand what you intended there, because what you wrote is not proper MATLAB syntax. For example, when MATLAB sees this generic form:
A(B)
it assumes that A is a function, that will be called with an operand B. So, when I write
(A)(B)
it gets confused. Is A a function, and B an argument? Computers need syntax to communicate with you.
Best Answer