Good afternoon,

I am attempting to construct a graph showing the trajectory of two variables over time, based on a coupled system of differential equations and some arbitrary initial conditions which I'll invariably end up changing later.

The model comes from a Latent Differential Equation model, a form of Structural Equation Modelling. A picture of the structural model I'm trying to build is attached below. From it, a coupled system of differential equations can be formed. I'm trying to plot a graph so I can show the behaviour over time based on different coefficients. As such, I'm trying to make a diagram which enables me to manipulate these coefficients. The bulk of my code is below:

sol[etax_, zetax_, gammay_, gammaydot_, etay_, zetay_, gammax_, gammaxdot_] := NDSolve[{
x''[t] - etax*x[t] - zetax*x'[t] - gammay*y[t] - gammaydot*y'[t] == 0,
y''[t] - etay*y[t] - zetay*y'[t] - gammax*x[t] - gammaxdot*x'[t] == 0,
x[0] == 0.1,
x'[0] == 0.1,
y[0] == 0.1,
y'[0] == 0.1},
y, {x, 0, 10}]
Plot[Evaluate[y[x] /. sol[etax, zetax, gammay, gammaydot, etay, zetay, gammax, 
gammaxdot]], {x, 0, 10},PlotRange -> {Automatic, {-10, 10}}],
{{etax, 1, "etax"}, -3, 3, Appearance -> "Labeled"},

When attempting this, I get a large list of warning messages. I am a little new to the Mathematica/Differential Equations circuit so have probably made a rookie error somewhere, but would really appreciate if anyone could offer any corrections or recommendations which help me with this model building.

Many thanks,

Structural Model Diagram

  • $\begingroup$ Best to supply all of the minimal amount of code the replicates the issue. $\endgroup$
    – Jagra
    Oct 19, 2020 at 17:51
  • $\begingroup$ A couple of observations: (1): Within the NDSolve in your sol function, I think you want== (Equal, returns True if lhs and rhs are identical) rather than =(Set). (2) The NDSolve does not specify a domain for t, again, I think you want something, e.g., like {x, 0, 10}, {t, 20} at the end of the NDSolve using whatever appropriate values you need for t. I don't see much else one can do to help without more of your code. $\endgroup$
    – Jagra
    Oct 19, 2020 at 18:12

1 Answer 1


Your NDSolve code is not valid: you should solve for the unknown functions x and y for a range {t,0,tmax}. After fixing this issue sol works. You can then incorparate the method into a Manipulate function e.g.:


Parametric plot

You could use a similar approach to using Plot to plot the x and y component over t instead of the using ParametricPlot or you could use ParametricPlot3D to plot x, y and t simultaneously.

  • $\begingroup$ Thank you very much for your feedback on this, the diagram works perfectly now. A 3D plot would probably better demonstrate what I'm trying to achieve, so I will adjust the code to create that. Thank you for the suggestion too. $\endgroup$
    – DAB77
    Nov 2, 2020 at 11:08

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.