How to Draw Two Graphs on the Same Axis in MATLAB?

  • Context: MATLAB 
  • Thread starter Thread starter MathematicalPhysicist
  • Start date Start date
  • Tags Tags
    Drawing Graph Matlab
Click For Summary
SUMMARY

This discussion focuses on plotting two graphs on the same axis in MATLAB, specifically using the functions defined by the equations \(\frac{1}{2}m\omega^2A^2e^{-\gamma t}[1+\frac{\gamma}{2\omega}\sin(2(\omega t+\phi))+\frac{\gamma^2}{2\omega}\cos^2(\omega t+\phi)]\) and \(\frac{1}{2}m\omega^2A^2e^{-\gamma t}\). The user is advised to create a time vector using t=linspace(0,6*pi,200) and to plot the functions using plot(t, func1, t, func2);. This approach allows for visual comparison of the two functions over a specified range of periods.

PREREQUISITES
  • Basic understanding of MATLAB syntax and functions
  • Familiarity with mathematical functions and plotting
  • Knowledge of parameters such as A, m, and γ in the context of graphing
  • Ability to manipulate vectors and matrices in MATLAB
NEXT STEPS
  • Learn about MATLAB function files and how to define custom functions
  • Explore MATLAB's plotting options, including hold on for multiple plots
  • Study the use of linspace for generating vectors in MATLAB
  • Investigate the implications of varying parameters A, m, and γ on graph shapes
USEFUL FOR

This discussion is beneficial for novice MATLAB users, students learning mathematical modeling, and anyone interested in visualizing complex functions on the same axis.

MathematicalPhysicist
Science Advisor
Gold Member
Messages
4,662
Reaction score
372
I need to draw two graphs in the same axis in matlab, and I'm novice in matlab, so if someone can type the code for this it will be much appreciated, this is the only way I can learn right now.
the graphs are of:
\frac{1}{2}m\omega^2A^2e^{-\gamma t}[1+\frac{\gamma}{2\omega}sin(2(\omega t+\phi)+\frac{\gamma^2}{2\omega}cos^2(\omega t+ \phi)]
and \frac{1}{2}m\omega^2A^2e^{-\gamma t}
where A,m and gamma are arbitrary parameters, and \omega_0/\gamma=10
and \omega=\sqrt{\omega_0^2-1/4\gamma^2}
I need that the graph will span over a number of periods.

As I said I'm novice and not sure how to handle this, and reading the help may take more time for me.

thanks in advance.
 
Physics news on Phys.org
Set your time vector to be t=linspace(0,6*pi,200) which will give you a vector of 200 points evenly spaced between 0 and 6 \pi. We can adjust this later if you wish.

Write a function file with the outputs as your two funcitons above. To plot them on th esame axis, the command is plot(t, func1, t, func2); which will give you two lines.

if you don't get it, I wrote a couple of lines of code to help.
 
Last edited:

Similar threads

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