Why am I getting: "invalid syntax at "(" .A might be missing a closing ")"

7 ビュー (過去 30 日間)
Jamie Al
Jamie Al 2021 年 10 月 8 日
コメント済み: Jamie Al 2021 年 10 月 8 日
What is messing here??
source = ((-4*A^2*alpha)-(9*B^2*alpha))*(cos^2( (2*A) * XX).* sin^2( (3*B) * YY))...
-( (5/2)*4*A^2*alpha+(5/2)*9*B^2*alpha)*(cos( (2*A) * XX).* sin( (3*B) * YY))...
+ ((4*A^2*alpha)*(sin^2((2*A) * XX).* sin^2( (3*B) * YY)))...
+ ((9*B^2*alpha)*(cos^2((2*A) * XX).* cos^2( (3*B) * YY))));
Error at first line where the cosine squared is
(cos^2( .. %underneath the paranthesis infront of cos^2
I don't understand???
  2 件のコメント
Stephen23
Stephen23 2021 年 10 月 8 日
編集済み: Stephen23 2021 年 10 月 8 日
The functions COS and SIN require an input argument, so many of your function calls are invalid:
cos^2(..) % invalid sytanx (COS has no input)
cos(..)^2 % valid syntax
I suspect that you actually want POWER .^ and not MPOWER ^
Jamie Al
Jamie Al 2021 年 10 月 8 日
I see!! Thanks!

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2021 年 10 月 8 日
In MATLAB, cos^2(x) and sin^2(x) are not valid operations. These will be interpreted as cos()^2(x) and sin()^2(x) which would involve invoking cos or sin with no parameters, and trying to raise the result to an expression that as 2 followed by an expression in () ... which would be intepreted as an invalid indexing operation since constants such as 2 cannot be indexed.
You need to instead code cos(x)^2 and sin(x)^2 .
... You should probably vectorize along the way.
  1 件のコメント
Jamie Al
Jamie Al 2021 年 10 月 8 日
Is this correct here:
cos((2*A) * XX).^2 .*..
I mean the place of the dot operator?

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2021 年 10 月 8 日
You are missing an operator, multiplication operator at many places.
(cos^2*( .. %underneath

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by