graph the function, f(x1,x2) = -(x1/2) - (3*x2 / 2) using contour function in matlab

Here's how you can graph the function f(x1,x2) = -(x1/2) - (3*x2 / 2) using contour function in matlab:

  1. Define the function:
main.m
f = @(x1,x2) -(x1/2) - (3*x2 / 2);
35 chars
2 lines
  1. Create a grid of x1 and x2 values using meshgrid function:
main.m
[x1,x2] = meshgrid(-10:0.1:10, -10:0.1:10);
44 chars
2 lines
  1. Evaluate the function at each point on the grid:
main.m
z = f(x1,x2);
14 chars
2 lines
  1. Use contour function to create a contour plot:
main.m
contour(x1,x2,z);
xlabel('x1');
ylabel('x2');
46 chars
4 lines

This will create a contour plot of the function f(x1,x2) = -(x1/2) - (3*x2 / 2).

Note: Contour plots show the level sets of the function on the 3D graph.

related categories

gistlibby LogSnag