2
$\begingroup$

I'm really n00b in Mathematica, so please bear with me, as this seems to be my only option to learn how to do what I wany to do.

I have a system of two differential equations:

y' = v[t]
v'[t] = -a^2y

Now, assuming I know the solution of this system is: $y = cos(a\,t),\ v = -a\,sin(a\,t)$, I want to plot the integral curve of the two, on the v-y surface, with a t getting values from 0 to 2 π.

I've tried various combinations of StreamPlot, VectorPlot and many other functions, without any success, although I think it's suppose to be really simple. I've tried also to make a plot in 3D with VectorPlot3D, but to no avail.

I'll appreciate any help.

$\endgroup$
2
  • $\begingroup$ You are wrong. There is a good way to learn more apart from only asking questions. Here: mathematica.stackexchange.com/questions/18/… you will find lots of resources to learn Mathematica. Have fun! $\endgroup$ Commented Jul 10, 2014 at 7:12
  • $\begingroup$ Besides, this: a^2yis an error. Mma reads it as "a to the power of 2y", while you evidently mean "a squared times y. You should have written a^2*y. Finally, have a look into Menu/Help/Documentation Center/NDSolve/BasicExamples/System of ordinary differential equations. You will find there the answer to the analogous question. $\endgroup$ Commented Jul 10, 2014 at 7:15

2 Answers 2

4
$\begingroup$

one way, if I understand you right (even though I think this will be closed :)

Clear[v, t, y];
a = 9;
eq1 = y'[t] == v[t];
eq2 = v'[t] == -a^2  y[t];
sol = First@DSolve[{eq1, eq2, y[0] == 1, v[0] == 2}, {v[t], y[t]}, t];
ParametricPlot[Evaluate@{v[t] /. sol, y[t] /. sol}, {t, 0, 1}]

Mathematica graphics

(as others mentioned, you have lots of syntax errors there)

$\endgroup$
3
  • $\begingroup$ Thanks, this is really what I wanted, with small addition - I want to plot it as vector (with direction) and that's why I've tried to do it with VectorPlot. As for the syntax errors - and this goes to Alexei as well - I didn't intended to write the accurate syntax here, this was only to explain the problem. Of course in Mathematice I used the correct syntax. $\endgroup$
    – Bak Itzik
    Commented Jul 10, 2014 at 7:28
  • $\begingroup$ Maybe you want to see something like StreamPlot[{-y, x}, {x, -1, 1}, {y, -1, 1}] ? $\endgroup$ Commented Jul 10, 2014 at 7:47
  • $\begingroup$ Not exactly. I want the result to be just like Nasser did, but with arrows along the curve, showing the 'direction' of the curve. $\endgroup$
    – Bak Itzik
    Commented Jul 10, 2014 at 10:02
4
$\begingroup$

Instead of explaining too much, here is some correct MMA-code for your problem. By studying it (and the documentation of MMA) in detail you will discover the answer to your question:

Clear[a, y, v, yy, vv, sol]

sol = 
  DSolve[{y'[t] == v[t] , v'[t] == -a^2 y[t], y[0] == 0, v[0] == 1}, {y[t], v[t]}, t];

{yy[t_, a_], vv[t_, a_]} = {y[t], v[t]} /. sol[[1]]

(* Out[71]= {Sin[a t]/a, Cos[a t]} *)

With[{a = 2},
 ParametricPlot[{yy[t, a], vv[t, a]}, {t, 0, 2 \[Pi]/a}, 
  AspectRatio -> Automatic]]

I have dropped the image here for simplicity.

Regards, Wolfgang

$\endgroup$
4
  • $\begingroup$ Please do not include the In[] and Out[] in the code, as it makes it hard to copy/paste as is. $\endgroup$
    – Nasser
    Commented Jul 10, 2014 at 7:36
  • $\begingroup$ Ok Nasser, thanks for your hint. $\endgroup$ Commented Jul 10, 2014 at 8:01
  • 1
    $\begingroup$ @Nasser Ins and Outs removed $\endgroup$ Commented Sep 29, 2016 at 7:36
  • $\begingroup$ @Nasser Thanks for upvoting. Actually, you should have punished me because I did it so late ;-) $\endgroup$ Commented Sep 29, 2016 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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