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

AI Thread Summary
To draw two graphs on the same axis in MATLAB, start by defining the time vector using t = linspace(0, 6*pi, 200), which creates 200 evenly spaced points between 0 and 6π. The two functions to plot are: 1. f1(t) = (1/2)mω²A²e^(-γt)[1 + (γ/2ω)sin(2(ωt + φ) + (γ²/2ω)cos²(ωt + φ)]2. f2(t) = (1/2)mω²A²e^(-γt)Here, A, m, and γ are arbitrary parameters, and ω is calculated as ω = sqrt(ω₀² - 1/4γ²) with ω₀/γ = 10.
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

Back
Top