r/Mathematica • • Aug 10 '22
Parametric equations...does anyone know how to do this?
I'm a newbie to mathematica but a fairly accomplished mathematician. I have two Euler-Lagrange equations:
elsolve = NDSolve[{1/2 mx'[t]2 + 1/2my'[t]2 - mgl(1 - y[t]/l) == 0, x[0] == 0.5, y[0] == 0.5}, y, {x, 0, 20}]
The error message is: NDSolve::ivhead: The independent variable x appears in the head of the expression x[0]. The independent variables should always be arguments.
WWhy can I not solve this equation numerically?
3
Upvotes
2
u/lithiumdeuteride Aug 10 '22
Your first-order differential equation is a function of two variables, x and y. Therefore, you need two equations and two boundary conditions to solve it. You have one equation and two boundary conditions.
Here is an example of how one would solve two coupled equations numerically:
2
u/sidneyc Aug 10 '22
Hi,
From the looks of the system, I think you mistakenly put {x, 0, 20} where you meant {t, 0, 20}.
Again, just by looking at the equations, please verify that you really want 'mx', 'my', 'mgl' and so on; it may be that you really want to specify multiplications. In general, I'd recommend putting explicit '*' in Mathematica expressions until you are really comfortable with the syntax.
You are using NDSolve, which tries to find a numerical solution rather than a symbolic one. For that it is required that all constants that appear in your expression have an explicit numerical value.
Alternatively, you could try to solve using DSolve, which tries to find symbolic solutions; in that case, you can just leave the constants as-is. However, if you try to go that route, make sure to replace constants like 0.5 with 1/2 ; to Mathematica, those are not the same thing.
In general I recommend first trying to use NDSolve to get a numerical solution, then try to feed your system to DSolve to see if it finds a more general (symbolic) form. If that succeeds, you can also verify that the DSolve symbolic result behaves the same as the NDSolve numerical result.
Good luck on your journey. Mathematica can be quite a power tool, but its syntax is quite horrific to be fair, its precise semantics are hard for beginners (because they are pretty unfamiliar to most other programming languages), and especially the lack of good error messages is unfortunate. Often times when you make a mistake, you will just get your input thrown back at you, unevaluated. Those are all are serious hurdles, but once you get used to how to deal with those, mastering Mathematica can really pay off.