Plotting Multiple Equations on One Graph in MATLAB?

Click For Summary
SUMMARY

This discussion focuses on plotting piecewise functions in MATLAB, specifically the function defined as f(t) = 2t for 0 ≤ t < 2 and f(t) = t² - 3 for 2 ≤ t. The user chief10 provided a solution using the ezplot function to plot both equations on the same graph. The correct implementation involves using 'hold on' to overlay the plots of the two equations within the specified range of 0 ≤ t ≤ 4.

PREREQUISITES
  • Familiarity with MATLAB programming environment
  • Understanding of piecewise functions
  • Knowledge of the ezplot function in MATLAB
  • Basic graphing concepts in mathematics
NEXT STEPS
  • Learn how to use MATLAB's 'hold on' and 'hold off' commands for overlaying plots
  • Explore advanced plotting techniques in MATLAB, such as using 'fplot' for more complex functions
  • Investigate MATLAB's symbolic math toolbox for handling equations
  • Study piecewise function definitions and their graphical representations
USEFUL FOR

Students, educators, and engineers who need to visualize piecewise mathematical functions using MATLAB for academic or professional purposes.

chief10
Messages
78
Reaction score
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
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
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
9K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
3
Views
2K