# simple calculus

## Recommended Posts

Hello Its been way to long since I practiced my calculus....hence I am stuck on a fairly basic problem...I have an objects(missile) initial velocity, acceleration and the distance it must travel to reach an end point. So I want to calculate the time it will take to do this. I figure all this can be represented by the following equation: vel*time + accel*time^2 - dist = 0 What are the various ways to solve this programatically? Thank you in advance for your help :)

##### Share on other sites
You can use the Quadratic Formula.

t1 = (-vel + sqrt(vel^2 - 4*accel*(-dist))) / (2*accel)
t2 = (-vel + sqrt(vel^2 - 4*accel*(-dist))) / (2*accel)

##### Share on other sites
I completly forgot about that...awesome, thankyou....just wondering what the issues are in terms of selecting the 'correct' solution and situations involving a square root of zero?

p.s. I think you made 2 small mistakes in your formulae...there should be a 'plus and minus' solution...and you have '-dist' ..should be just dist in that case because you already have a negative in tht term.

##### Share on other sites
In this case you are only concerned with the positive case (for a positive time value) so you don't need the plus/minus.

And (-dist) is in the formula because "c" in the equation is "-dist"

##### Share on other sites

vel*time + 0.5*accel*time^2 - dist = 0

There's Maclaurin expansions for you.

##### Share on other sites
You do need the plus minus if you want to deal with problems like "the object is accellerating faster than the missile, but starts out moving slower".

The solution to:
ax^2 + bx + c = 0
for x from the complex numbers is
x in {[-b +/- sqrt(b^2-4ac)] / 4a}

It can return 0, 1 or 2 solutions. It should have a "fudge factor" epsilon as well (if b^2-4ac is -.00000001, quite possibly you shouldn't answer "there is no solution", because rounding errors may be causing problems...).

##### Share on other sites
Thank you for the advice... :)

Let me specifically describe the problem...its for a stationary SAM system....it sees a helicopter and want to fire a missile at it.....However I want it to do a simple anyalysis of the helipcopter's velocity so that it will fire the missile along a vector that it thinks will intersect that of the helicopter...based on how it viewed the helicopter when it fires.

Anyways I have it working so that missile is fired at the predicted position...Only problem is that because the prediction is based on the ideal maths case...and the missile(and helicopter) move based a timestep simulation there is an error involved. I have forgotten exactly how, but I seem to remember a remedy involving using an average value of velocity(avg vel at start and end of timestep) for each timestep to reduce or eliminate the error....

[Edited by - bobbinus on April 25, 2006 8:35:53 AM]

##### Share on other sites
This may not be what you are looking for, but you could make the missle track the helicopter once fired like a real-life SAM. Just keep track of the vector between the missle and chopper and turn the missle accordingly as it flies.

##### Share on other sites
JonWoyame is right you should use a tracking algorithm instead of calculating the impact position based on standard motion equations. What happens for example if the helicopter has a unpredictable flightpath? A tracking missile wont bother with that it is just tries to hit the helicopter. You will also be able to add whatever dynamics you want to the system like possibility for the missiles to switch targets during flight.

##### Share on other sites
Another option is the "binary search" solution (or "newton's method" if you want to get fancy).

Let S be an aiming solution. From your model, the only thing under control is the angle of fire. Define "angle of 0" to be "aiming right at where the target is right now".

Let f(S) be the distance your missile ends up being from the target as it passes by it under the solution S. Negative means "missed on left", positive means "missed on right".

Let S_0 be a firing solution such that f(S_0) < 0 and S_1 be a firing solution such that f(S_1) > 0.

Then, you can probably do a binary search between S_0 and S_1 for the correct aim.

Some "gotyas":
1> You may sometimes have to "give up" and say "I can't figure out how to shoot at the target". You don't want to search forever -- have a fixed limit on the number of search iteratons.

2> You need to find S_0 and S_1. You could just make a bunch of guesses until you get lucky. :)

3> A "dictionary" search will probably converge faster than a simple binary search (ie, if S(S_0) is -1 and S(S_1) is 100, pick your next point as being closer to S_0 than S_1).

Let us know how your solution works. =)

##### Share on other sites
"Simple Calculus" -- I think we have an oxymoron here. LoL. =)

Okay, I was just kidding. I've never done anything in calculus, so I don't know. I DO know that it's not the easiest thing in the world. =P

##### Share on other sites
Quote:
 Original post by Sneftelbobbinus, your original formula is wrong. it should read:vel*time + 0.5*accel*time^2 - dist = 0There's Maclaurin expansions for you.

How'd you get a Maclaurin from this? Sorry if I'm being naiive here, but wouldn't you just have to do some simple integrations? (It's kinda sad though... I've got the Calculus BC AP test three days from now and I had to think pretty hard on this)

p(t) = Position (distance); v(t) = p'(t) = Velocity; a(t) = v'(t) = p"(t) = Acceleration
a(t) is constant (replace it as 'a')
v(t)=INT( a * dt ) = a*t + v(0)
p(t)=INT( v(t) dt ) = a/2*t^2 + v(0)*t + p(0)
Ignore p(0) since we're just measuring distance with the position
p(t) = a/2*t^2 + v(0)*t
And then go on from there.

Well, at least I'm getting the same thing.

##### Share on other sites
Quote:
Quote:
 Original post by Sneftelbobbinus, your original formula is wrong. it should read:vel*time + 0.5*accel*time^2 - dist = 0There's Maclaurin expansions for you.

How'd you get a Maclaurin from this? Sorry if I'm being naiive here, but wouldn't you just have to do some simple integrations? (It's kinda sad though... I've got the Calculus BC AP test three days from now and I had to think pretty hard on this)

p(t) = Position (distance); v(t) = p'(t) = Velocity; a(t) = v'(t) = p"(t) = Acceleration
a(t) is constant (replace it as 'a')
v(t)=INT( a * dt ) = a*t + v(0)
p(t)=INT( v(t) dt ) = a/2*t^2 + v(0)*t + p(0)
Ignore p(0) since we're just measuring distance with the position
p(t) = a/2*t^2 + v(0)*t
And then go on from there.

Well, at least I'm getting the same thing.

A smooth function can be represented by a polynomial of the form

f(t) = sum{i=0,inf} (t-t0)^i D_i[f(t0)] / i!

where D_i[...] means the ith derivative of whatever is in the brackets with respect to t. This is called the Taylor series. If t0 is zero, it is the Maclaurin series.

The approach you have used is similar to one of the ways in which the Taylor series can be derived. Notice in your method that if acceleration was not constant you would still have an integral remaining. This is not a bad thing and it is useful for estimating errors in Taylor series if you truncate them. The integral represents the "error" and using the mean value theorem you can sometimes get useful bounds on its magnitude.

##### Share on other sites
Okay, he was taking the Maclaurin of the position function... For some reason, I couldn't grasp that idea before...

*In an attempt to redeem myself*
As for the whole Taylor/Maclauring thing, we've been learning that in class for a while (about a month and a half)... We use different variable names (*gasp*), but... yeah.

To get slightly off-topic: What I hated - Not knowing how to find the error of an alternating series. Oh, how painful it was to see how simple it was.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628345
• Total Posts
2982187

• 9
• 24
• 9
• 9
• 13