How to plot 3D surface using surf [y*(3x^2+y^2)] / (x^2+y^2)^2 ?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Anshuman S
el 23 de Oct. de 2017
Respondida: DASHRATH
el 6 de Sept. de 2022
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 comentarios
Respuesta aceptada
Walter Roberson
el 23 de Oct. de 2017
Z = (Y .* ((3*(X.^2) + Y.^2) ) ./ ((X.^2 + Y.^2).^2));
2 comentarios
Walter Roberson
el 24 de Oct. de 2017
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.
Más respuestas (1)
DASHRATH
el 6 de Sept. de 2022
[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 comentarios
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!