Parse error at ')'when plotting surface plot

3 ビュー (過去 30 日間)
Eric Yeh
Eric Yeh 2019 年 3 月 3 日
コメント済み: Walter Roberson 2019 年 3 月 4 日
Hey, I'm trying to plot the surface plot z=(x^2-ycos(x))/sqrt(x^2+y^2)
Everytime I try to run the program though, it keeps coming up with the error: "parse error at ')': usage might be invalid Matlab syntax" after the cos(x.) in the equation. Any help would be much apreciated :)
x=-5:.1:5;y=x;[x,y]=meshgrid(x,y);
z = (x.^2-y.*cos(x.))/sqrt(x.^2+y.^2);
surfc(z)
xlabel('x axis')
ylabel('y axis')

採用された回答

Walter Roberson
Walter Roberson 2019 年 3 月 3 日
編集済み: Walter Roberson 2019 年 3 月 3 日
In MATLAB, periods in source code must be in one of the following contexts:
  1. in a comment
  2. in a single-quoted string
  3. in a double-quoted string (R2017a and later)
  4. proceeded by a numeric digit, such as 35.
  5. followed by a numeric digit, such as .35
  6. followed immediately by * or ^ or / such as 3.*5 or 3.^5 or 3./5
  7. between two variable names, or two parts of a package name, indicating structure access or property access or method invocation, such as MyStruct.field7 or matlab.lang.makevalidname
  8. after a variable name but before a ( indicating dynamic field access, such as MyStruct.(fn{3})
In your expression cos(x.) this is not any of the cases.
MATLAB does not permit abbreviating floating point 0 as just plain . requiring instead 0 or 0. or .0 . And if it did accept plain . as 0, it would still be an error to have written cos(x 0) without an operator between the x and the zero.
  2 件のコメント
Eric Yeh
Eric Yeh 2019 年 3 月 3 日
Thanks for the help!
My professor said that having the variable as x. allows matlab to treat it as a vector.
However, when I try using it as x.0 or x.^1, it comes up with the error that there are missing ')' or a warning that "the matrix is singular to working precision". When I try to plot the latter scenario, nothing comes up in the figure.
Would you have any ideas on how to write out the equation with proper syntax and be plotted?
Walter Roberson
Walter Roberson 2019 年 3 月 4 日
Use ./ instead of /

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by