How to plot 3D surface using surf [y*(3x^2+y^2)] / (x^2+y^2)^2 ?
2 ビュー (過去 30 日間)
古いコメントを表示
I have used the following command .
[X,Y] = meshgrid(1:0.5:10,1:20);
Z =(Y*((3*(X.^2) + Y.^2) )/((X.^2 + Y.^2).^2));
surf(X,Y,Z)
This is the error which I am getting
Error using *
Inner matrix dimensions must agree.
Error in Mse302 (line 2)
Z =(Y*((3*(X.^2) + Y.^2) )/((X.^2 + Y.^2).^2));
0 件のコメント
採用された回答
Walter Roberson
2017 年 10 月 23 日
Z = (Y .* ((3*(X.^2) + Y.^2) ) ./ ((X.^2 + Y.^2).^2));
2 件のコメント
Walter Roberson
2017 年 10 月 24 日
The problem is that * is the algebraic matrix multiplication operation. In A*B, size (MxN)*(PxQ) must have N=P and produces a MxQ output -- size size(A,2) == size(B,1) .
Your X and Y are 20 x 19.
The ((3*(X.^2) + Y.^2) ) part of your expression is adding two 20 x 19 matrices, so the result is 20 x 19.
The Y * part before that means you have a 20 x 19 * a 20 x 19. size(20x19,2) ~= size(20x19, 1) so the use of * was invalid. If you had happened to use meshgrid to create 20 x 20 instead of 20 x 19 then the * would have been permitted, 20x20 * 20x20 giving 20x20 -- but it would probably have been mathematical nonsense for the purposes of your formula.
With the * converted to .* then the (Y .* ((3*(X.^2) + Y.^2) ) part is going to give 20 x 19. The ((X.^2 + Y.^2).^2)) part would also be 20 x 19. You would then have 20x19 / 20x19 .
The / operator in MATLAB is the Matrix Right Divide operator, with B/A being similar to B*inv(A). The operator has several uses including linear least squares and solving simultaneous linear equations. The operator requires that the number of columns be the same between the two sides -- which was the case for you. However, it is rather unlikely that this is the operation you intended to calculate.
その他の回答 (1 件)
DASHRATH
2022 年 9 月 6 日
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = (Y .* ((3*(X.^2) + Y.^2) ) ./ ((X.^2 + Y.^2).^2));
surf(X,Y,Z)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!