Using integration in Java

So I am trying to calculate the current position of a vehicle at a constant acceleration, referring to: Acceleration, velocity, and Position

I am trying to get the integral of the current speed in order to get the position at time T.

Anyone has any idea how to do it? I am not that good in Maths.

Re: Using integration in Java

Quote:

I am trying to calculate the current position of a vehicle at a constant acceleration ... I am not that good in Maths.

The link you give contains the formula you would use. It's the one in the second box:

x(T) = x(0) + v(0)T + 1/2 aT^2

As with any equation you have to get a clear idea of what each thing stands for and which of them are "known" and which are "unknown".

T is the time. It is a variable: ie it is always some definite amount (you can regard it as "known"). Other things may depend on the value T has.

x(T) is the position at time T. This is unknown: in fact it is **the** unknown with which you start your problem. "I am trying to calculate the current position..."

x(0) is the position at time zefro. This is a known quantity (see below).

v(0) is the velocity at time zero. This is a known quantity (see below).

a is the (constant) acceleration. Again it is a known quantity.

-----

If we are trying to calculate the current position of a vehicle it is not enough to know the acceleration only. (For example I can figure out the acceleration of the moon quite easily because I know how long it takes to go around the earth and google will tell me how far away it is: but I have no clue - without looking out of the window - about its current position.) We **also** need to know where it was and how fast it was going when the measurements started. This is what I called position and velocity at time zero. Without those extra pieces of information we can't tell the current position. That's why I described them as "known".

In many problems this "initial" information is given, or can be assumed. For example a drag racer has initial velocity zero (because of how drag racing works) and initial position zero (because it is convenient to define the starting line that way). Given these two facts the equation will reduce to

x(T) = 1/2 aT^2

and this tells us the current (at any time T) position of a drag racer which has constant acceleration a.

-----

What you have to do is write code that converts the equation in the second box to some Java code. Possibly it can be simplified like the drag racer if you know (or can assume or define) the initial position and/or velocity.

Re: Using integration in Java

Thank you so much!

yes my case is similar to drag racing as I am dealing with cars so I will be taking the initial position out of the equation.

thank you!

Re: Using integration in Java