Graphing z=x^2+(xy) in Matlab: What am I Doing Wrong?

  • MATLAB
  • Thread starter JoshHolloway
  • Start date
  • Tags
    Matlab
In summary, there are several reasons why a graph may not be showing up in Matlab, such as incorrect entry of the equation or values. To change the color or style of a graph, the "plot" command can be used with additional arguments. The difference between "plot" and "ezplot" is that "ezplot" is specifically for mathematical equations, while "fplot" can handle more complex equations. To add a title and labels to a graph, the "title", "xlabel", and "ylabel" commands can be used. Graphs can also be saved as images using the "saveas" or "print" commands.
  • #1
JoshHolloway
222
0
I want to graph the equation [tex] z = x^{2} + (xy) [/tex] in matlab, but I can't figure out how to do it.

Here is the code I am trying:

EDU>> [X,Y] = meshgrid(-10:.5:10);
EDU>> Z = X.^2 + X. * Y.;
EDU>> mesh(X,Y,Z, 'EdgeColor', 'black')


What am I doing wrong?
 
Physics news on Phys.org
  • #2
Anyone?
 
  • #3
What makes you think you're doing something wrong?

I can see one syntactical mistake (X. * Y.; should be X.*Y;) but otherwise it looks ok
 

1. Why is my graph not showing up in Matlab?

There could be several reasons why your graph is not showing up. First, make sure you have correctly entered the equation in the command window. Also, check that you have defined appropriate values for x and y. If the graph still does not appear, try adjusting the axis limits or using the "hold on" command to plot multiple graphs on the same figure.

2. How can I change the color or style of my graph in Matlab?

To change the color or style of your graph, you can use the "plot" command with additional arguments. For example, you can specify the color by adding a string argument after the equation, such as "plot(x,y,'r')" for a red line graph. You can also change the line style by adding a third argument, such as "plot(x,y,'--')" for a dashed line graph.

3. What is the difference between "plot" and "ezplot" in Matlab?

The "plot" command is used for plotting a specific set of data points, while "ezplot" is used for plotting mathematical equations. "ezplot" automatically generates a range of data points based on the given equation and plots them as a line graph. You can also use the "fplot" command for more complex equations that cannot be plotted with "ezplot".

4. How can I add a title and labels to my graph in Matlab?

To add a title and labels to your graph, you can use the "title", "xlabel", and "ylabel" commands. These commands take in a string argument that specifies the text to be displayed. You can also use the "legend" command to add a legend to your graph if you have multiple plots on the same figure.

5. Is there a way to save my graph as an image in Matlab?

Yes, you can save your graph as an image in several different formats such as PNG, JPEG, or PDF. To do this, you can use the "saveas" command and specify the desired file type and name. For example, "saveas(gcf,'mygraph.png')" will save the current figure as a PNG image. You can also use the "print" command to customize the size and resolution of the saved image.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
117
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
Back
Top