(xy^3)/(1+y^2) = 8/5 plot graph 2d in matlab

To plot the 2D graph of the equation (xy^3)/(1+y^2) = 8/5 in Matlab, follow these steps:

  1. Define the equation as a function of x and y:
main.m
eqn = @(x,y) (x*y.^3)./(1+y.^2) - 8/5;
39 chars
2 lines
  1. Generate a grid of x and y points using the meshgrid function:
main.m
[x,y] = meshgrid(-5:0.1:5);
28 chars
2 lines

This generates a grid of x and y points ranging from -5 to 5 with a spacing of 0.1.

  1. Evaluate the equation at each point in the grid to generate a matrix of z values:
main.m
z = eqn(x,y);
14 chars
2 lines
  1. Plot the graph using the contour or contourf function:
main.m
contourf(x,y,z,20);
xlabel('x');
ylabel('y');
colorbar;
56 chars
5 lines

or

main.m
contour(x,y,z,20);
xlabel('x');
ylabel('y');
colorbar;
55 chars
5 lines

The contourf function will create a filled-in contour map, while contour will create a contour map without fill.

The 20 parameter specifies the number of contour levels to display.

The xlabel, ylabel, and colorbar functions are optional and can be used to label the axes and add a colorbar to the graph.

related categories

gistlibby LogSnag