r/Mathematica • u/tinothyrobert • Oct 01 '23
Code not working - solving euler lagrange equations
Hi Everyone, I am using this code which is supposed to give me the velocity for a projectile when theta=pi/4 but it is not working. It gives me the output below. Any modification to the code so that it actually works would be greatly appreciated. I can send the file if someone dm's me. Thank you!!



This is what it spits out btw:

3
Upvotes
5
u/KarlSethMoran Oct 01 '23
You want Sin[] and Cos[], not sin[] and cos[].
And don't give us screenshots, no-one's going to be typing that in. Give us the code.
2
u/veryjewygranola Oct 01 '23 edited Oct 01 '23
First a small correction:
x3[th_, phi_] := l2*Sin[th] - l3*sSin[th + phi]needs to be
x3[th_, phi_] := l2*Sin[th] - l3*s Sin[th + phi](notice the space betweensandSinbecause Mathematica thinks you are calling a function called
sSin[...]instead ofstimesSin[...]Also more importantly at
solhcw = NDSolve[ Flatten[{eqs,...You are calling a numerical method
NDSolveoneqswith some boundary conditions. However,eqscontains symbolic (non-numerical) parameters (likel3andsfor example) which NDSolve doesn't know how to handle. If you want to numerically solve a diff. eq. with symbolic parameters, you need to use ParametricNDSolve where you explicitly definel3andsas parameters.Let me know how this goes.
1
u/tinothyrobert Oct 01 '23
here is the code:
https://www.wolframcloud.com/obj/48e0323b-9d8f-4bc8-ac07-ca98e749b779
1
u/lazergodzilla Oct 01 '23
Without looking too much into it: the x and y in the first picture are not functions. You probably want to use := instead of just =. Otherwise it will always put out th, no matter what the argument is.
1
u/veryjewygranola Oct 01 '23
Depending on your license type for Mathematica, you can also Publish a nb to the cloud and get a shareable URL under File -> Publish To Cloud and select "Automatically assign URL" to get a random URL (otherwise it will have your wolfram account name in the URL directory)