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

15 次查看(过去 30 天)
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));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by