problem using mesh. "Matrix is singular to working precision."

15 ビュー (過去 30 日間)
andré nilsson
andré nilsson 2018 年 3 月 16 日
コメント済み: andré nilsson 2018 年 3 月 16 日
I'm trying to plot a graident of a function using mesh and meshgrid but im getting the "Warning: Matrix is singular to working precision." when im trying to run the code. the graph is empty. is the problem that im divding with zero in my interval? how can I work around this?
if true
[X,Y] = meshgrid(-3:1:3);
f1=(3*X.^2*Y + 10*X*Y.^2)/(exp(X.^2) + 3*Y.^4) - (2*X*exp(X.^2)*(X.^3*Y + 5*X.^2*Y.^2))/(exp(X.^2) + 3*Y.^4)^2;
mesh(X,Y,f1);
end

採用された回答

Birdman
Birdman 2018 年 3 月 16 日
Actually, the problem is that you do matrix operation but instead, you need to do elementwise operation, which means using ./ and .* instead of / and *. Try this:
[X,Y] = meshgrid([-3:0.01:3]);
f1=@(X,Y) (3*X.^2.*Y + 10.*X.*Y.^2)./(exp(X.^2) + 3.*Y.^4) - (2.*X.*exp(X.^2).*(X.^3.*Y + 5.*X.^2*Y.^2))./(exp(X.^2) + 3*Y.^4).^2;
mesh(X,Y,f1(X,Y));
  1 件のコメント
andré nilsson
andré nilsson 2018 年 3 月 16 日
It works as it should now, thanks alot for the help!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by