09-07-2017 08:12 AM
I am trying to draw a projectile motion graph using MATLAB script. But not getting the graph. Can anyone please check my code and tell me what is the mistake.
I don't know how to take θ positive and negative when above and below the horizontal. How can I write the code for it?
Solved! Go to Solution.
09-07-2017 09:52 AM
I don't have the Matlab Toolkit, so I can't run your code.
Maybe you have to convert from degree to radians before feeding it into the sinus or cosinus function?
I hastly translated your script in plain Labview G code, this is what I get:
09-07-2017 10:02 AM
You're on the right track. I made the changes directly in the MATLAB node and while not familiar with the expressions used, produces a reasonable trace.
With such simple functions, the Mathscript node (if available), or even the formula node could be used instead.
09-07-2017 12:48 PM
This has nothing to do with LabVIEW, BUT...
If you shoot a projectile with a launch angle of 90deg (straight up in the air), it should come down on your head. Your result shows it landing quite a long distance away. So, I think your equation is wrong in the Matlab Script.
Got this equation from Wikipedia
Rearranging the terms to match your MathScript code, I get the following for "R":
R = d.*[sin(a)+A]
It's different than what you have. Try it and see if the results are more realistic.
09-07-2017 03:21 PM
Thank you for your reply. Do you think that it is something to do with the angle conversion from degree to radian?
09-07-2017 03:46 PM
Understood the mistake I have done. Thanks a ton.
09-07-2017 04:06 PM
@anny321dum wrote:
I don't know how to take θ positive and negative when above and below the horizontal. How can I write the code for it?
This got me thinking a little more. The Wikipedia formula doesn't model the motion well for negative launch angles. Going back to the quadratic equation, there are actually 2 solutions for the range. You need to use the "plus" for positive angles and "minus" for negative angles.
Here is a quick VI implementing positive/negative launch angle
09-07-2017 04:29 PM
I think it translates to your Matlab script as (please check my math):
R=d.*[sin(a)+A] for theta>0
R=d.*[sin(a)-A] for theta<0
and for special case of theta=0
R=v*sqrt(2*H/g)
09-13-2017 10:10 AM
Thank you very much for your reply. I got the correct vi.
09-14-2017 11:50 AM
I'm just curious:
have you translated the .vi from jamiva to the matlab node script language?
if yes, could you share this .vi?