How to plot 3D surface using surf [y*(3x^2+y^2)] / (x^2+y^2)^2 ?
1 次查看(过去 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!