ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Projectile motion

Solved!
Go to solution

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?

0 Kudos
Message 1 of 11
(10,491 Views)

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:

g-code_projectile.PNG

 

0 Kudos
Message 2 of 11
(10,448 Views)

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.

0 Kudos
Message 3 of 11
(10,442 Views)
Solution
Accepted by anny321dum

 

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.

 

script.JPG

 

Got this equation from Wikipedia

 

equation.PNG

 

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.

0 Kudos
Message 4 of 11
(10,424 Views)

Thank you for your reply. Do you think that it is something to do with the angle conversion from degree to radian?

0 Kudos
Message 5 of 11
(10,400 Views)

Understood the mistake I have done. Thanks a ton.

0 Kudos
Message 6 of 11
(10,396 Views)

@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.quad solution.jpg

 

Here is a quick VI implementing positive/negative launch angle

 

FP.JPG

Pos_Neg Angles.png

Message 7 of 11
(10,390 Views)

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)

Message 8 of 11
(10,381 Views)

Thank you very much for your reply. I got the correct vi.

0 Kudos
Message 9 of 11
(10,332 Views)

I'm just curious:

have you translated the .vi from jamiva to the matlab node script language?

 

if yes, could you share this .vi?

0 Kudos
Message 10 of 11
(10,312 Views)