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

1 回表示 (過去 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)
  2 件のコメント
KSSV
KSSV 2016 年 9 月 8 日
what is sigma_net function? On seeing this function only one can help you out..
Walter Roberson
Walter Roberson 2016 年 9 月 8 日
sigma_net is posted right there above the "figure" command.

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

回答 (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 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