I am trying to plot my code using meshgrid command for three variables but I receive an error message

2 次查看(过去 30 天)
F = [-40:20:40];
x = linspace(0.1,0.8,length(F));
y = linspace(0.1,0.4,length(F));
sigma_p = @(x,y) F./(.8.*x.*y);
sigma_mx = @(x,y) (F.*y)./(1./12.*(x).*(y).^3);
sigma_my = @(x,y) (F.*x)./(1./12.*(y).*(x).^3);
sigma_net = @(x,y) sigma_p(x,y) + sigma_mx(x,y) + sigma_my(x,y);
figure
plot3(x, y, sigma_net(x,y))
[X,Y] = meshgrid(x,y);
Z = sigma_net(X,Y)
mesh(X,Y,Z)

回答(1 个)

Walter Roberson
Walter Roberson 2016-9-8
The error message is
Error using ./
Matrix dimensions must agree.
Error in @(x,y)F./(.8.*x.*y)
Error in @(x,y)sigma_p(x,y)+sigma_mx(x,y)+sigma_my(x,y)
You carefully created x and y to be the same length as F, but you are calling with X and Y which is a 2D square grid, and that 2D grid is not the same size as F.
Solution:
sigma_p = @(x,y) repmat(F, size(x,1), 1) ./ (.8.*x.*y);
sigma_mx = @(x,y) (repmat(F, size(x,1), 1) .*y)./(1./12.*(x).*(y).^3);
sigma_my = @(x,y) (repmat(F, size(x,1), 1).*x)./(1./12.*(y).*(x).^3);

类别

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