Plotting Multiple Equations on One Graph in MATLAB?

In summary, to plot multiple equations on one graph in MATLAB, use the "hold on" command. You can change the color or style of each equation by using the "color" and "linestyle" arguments in the "plot" command. To add a legend to a graph with multiple equations, use the "legend" function. It is possible to plot equations with different x and y ranges on the same graph by using the "axes" function. Finally, you can plot equations with different variables on the same graph by using the "ezplot" function or defining the variables as vectors or matrices in the "plot" command.
  • #1
chief10
78
0

Homework Statement



Does anyone know how to do this? Let's say I had the equation:

f(t) =
|2t, 0≤ t < 2
|(t^2)-3, 2≤t

how would you plot this over 0≤ t ≤4 in Matlab?


Homework Equations



-

The Attempt at a Solution



I've tried ezplot but i can't manage getting both equations on the same graph

Thanks guys and girls.

-chief10
 
Physics news on Phys.org
  • #2
worked it out!

if anyone is interested the code is belowsyms x y
ezplot(function, [xmin,xmax])
hold on
ezplot(function2, [xmin,xmax])
hold off
 

1. How do I plot multiple equations on one graph in MATLAB?

To plot multiple equations on one graph in MATLAB, you can use the "hold on" command. This allows you to plot multiple equations on the same figure without erasing the previous plots.

2. Can I change the color or style of each equation on the graph?

Yes, you can change the color or style of each equation on the graph by using the "color" and "linestyle" arguments in the "plot" command. For example, "plot(x,y,'color','red','linestyle','--')" will plot the equation with a red dashed line.

3. How do I add a legend to a graph with multiple equations?

To add a legend to a graph with multiple equations, you can use the "legend" function after plotting all the equations. You can specify the labels for each equation in the legend as well.

4. Can I plot equations with different x and y ranges on the same graph?

Yes, you can plot equations with different x and y ranges on the same graph by using the "axes" function. This allows you to specify the x and y limits for each equation separately.

5. Is it possible to plot equations with different variables on the same graph?

Yes, it is possible to plot equations with different variables on the same graph in MATLAB. You can use the "ezplot" function, which allows you to specify the variables for each equation. Alternatively, you can also use the "plot" command by defining the variables as vectors or matrices.

Similar threads

  • Calculus and Beyond Homework Help
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
Replies
1
Views
7K
  • Calculus and Beyond Homework Help
Replies
2
Views
3K
  • Calculus and Beyond Homework Help
Replies
3
Views
551
  • Calculus and Beyond Homework Help
Replies
16
Views
1K
  • Calculus and Beyond Homework Help
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
Replies
2
Views
508
  • Calculus and Beyond Homework Help
Replies
1
Views
421
  • Calculus and Beyond Homework Help
Replies
4
Views
926
Replies
1
Views
1K
Back
Top