Clear Filters
Clear Filters

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

2 views (last 30 days)
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)

Answers (1)

Walter Roberson
Walter Roberson on 8 Sep 2016
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);

Community Treasure Hunt

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

Start Hunting!