Mesh and Contour not plotting correctly
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
This is in regards to F2 in the code below. I graphed the meshplot on wolfram as well as saw how one of my classmates did it. Their's look the same however mine looks different. Not sure why F2 isn't being plotted correctly. It should have a different shape with two minima at the center. MATLAB output is shown first (screen snip) along with the Wolfram alpha output (assumed correct). 
Any help/suggestion is greatly appreciated. 


x1 = -10:0.1:10;
x2 = -10:0.1:10;
[X1,X2] = meshgrid(x1,x2);
F1 = (X1.^2 + X2.^2 + (4*X1) - (2*X2));
F2 = ((5*X1.^2) + (X1.^4) - (9*(X1.^2)*X2) + 3*(X2.^2) + (2*X2.^4) + (0.25*X1));
subplot(2,2,1); mesh(X1,X2,F1); title('F_1');
subplot(2,2,2); mesh(X1,X2,F2); title('F_2'); 
subplot(2,2,3); contour(X1,X2,F1); title('F1 Contour');
subplot(2,2,4); contour(X1,X2,F2); title('F2 Contour'); 
0 comentarios
Respuestas (1)
  Star Strider
      
      
 el 10 de Mzo. de 2020
        I slightly changed your code to make it a bit less confusing (creating ‘x’ and ‘y’ and ‘X’ and ‘Y’): 
x = -10:0.1:10;
y = -10:0.1:10;
[X,Y] = meshgrid(x,y); 
 There is one error.  You need to do element-wise multiplication:  
F2 = ((5*X.^2) + (X.^4) - (9*(X.^2).*Y) + 3*(Y.^2) + (2*Y.^4) + (0.25*X));
                                   ↑ ← HERE
They now appear to be the same.  
0 comentarios
Ver también
Categorías
				Más información sobre Contour 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!

