0
$\begingroup$

I am trying to plot a solution of a differential equation system. This is what I have:

eqn = {x''[t] + w^2*x[t] == 0, y[t] == x'[t]}; w = 1;
sol = DSolve[eqn, {x[t], y[t]}, t] 

and i need to plot 3 graphs x[t], y[t] and y[x]. I learned how to build the first two,

Plot[Evaluate[x[t] /. sol /. {C[1] -> 1, C[2] -> 1}], {t, 0, 10}]
Plot[Evaluate[y[t] /. sol /. {C[1] -> 1, C[2] -> 1}], {t, 0, 10}]

and i dont know how to build last y[x] and how to understand this. I add photo my task. enter image description here

$\endgroup$
2
  • $\begingroup$ You meant to say y[t] vs x[t]? if yes then ParametricPlot[ Evaluate[{x[t], y[t]} /. First[sol] /. {C[1] -> 1, C[2] -> 1}], {t, 0, 10}]? $\endgroup$ – zhk Mar 4 '17 at 17:01
  • $\begingroup$ I hope this is what I need. thx $\endgroup$ – Skadi Mar 4 '17 at 17:16
2
$\begingroup$

This is more of a Mathematics question.

eqn = {x''[t] + w^2*x[t] == 0, y[t] == x'[t]}; w = 1;
sol = DSolve[eqn, {x[t], y[t]}, t];
xt = FullSimplify[x[t] /. sol /. {C[1] -> 1, C[2] -> 1}][[1]]

$$x(t)=-\frac{\sin(t)}{2}$$

yt = FullSimplify[y[t] /. sol /. {C[1] -> 1, C[2] -> 1}][[1]]

$$y(t)=-\frac{\cos(t)}{2}$$

Now, recalling the trignometric identity and using the appropriate forms of the above two solutions,

$$1=\cos^2(t)+\sin^2(t)=4y^2+4x^2,$$

which gives equation of circle $x^2+y^2=1/4$ with radius $1/2$. Thus, your $y=f(x)$ is

$$y=\pm\sqrt{\left(\frac{1}{2}\right)^2-x^2}$$.

Plot[{Sqrt[(1/2)^2 - x^2], -Sqrt[(1/2)^2 - x^2]}, {x, -0.5, 0.5}, AspectRatio -> Automatic]

As I suggested in comment, the appropriate command to use is ParametricPlot.

In a parametric plot, you give both the $x$ and $y$ coordinates of each point as a function of a third parameter, say $t$.

Plotting (drawing) the circle with radius $1/2$ combine with parametric plot, we will see that both are the same,

Show[ParametricPlot[ {xt, yt}, {t, 0, 10}], ContourPlot[(x)^2 + (y)^2 == 1/4, {x, -5, 5}, 
                    {y, -3, 3}, ContourStyle -> {Red, Directive[Dashed]}]], Frame -> True]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.