#### Archived

This topic is now archived and is closed to further replies.

# How do I solve for time?

This topic is 5945 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

y=-1/2gt^2+vt+yi How do I solve this for t?

##### Share on other sites
Hi,

here''s my solution:

y = -1/2gt^2 + vt +yi // - y
0 = -1/2gt^2 + vt + yi -y

//abc formula??? (I don''t know the English name)
t1= -v/(2*(-1/2g)) + sqrt( (v/(2*(-1/2g)))^2 -((yi-y)/(-1/2g)) )
t1= v/g + sqrt( v^2/g^2 + (yi-y)/(1/2g) )

t2= -v/(2*(-1/2g)) - sqrt( (v/(2*(-1/2g)))^2 -((yi-y)/(-1/2g)) )
t2= v/g - sqrt( v^2/g^2 + (yi-y)/(1/2g) )

cLE

##### Share on other sites
Yes, we call it the "quadratic" formula:

if At2 + Bt + C = 0

then

t = (-B + sqrt(B2 - 4AC)) / (2A)or  t = (-B - sqrt(B2 - 4AC)) / (2A)

See, there are two possible values of t.

You would choose the t that is physically consistent. For example, it might not make sense to choose a value of t that is negative.

So in this case just set:

A = -1/2g
B = v
C = yi - y

Something for you to think about...what if B^2 - 4AC is negative?

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

##### Share on other sites
I foregot and had a brain fart. It is just the quadratic equation.

##### Share on other sites
Or you can use Polysolve on a TI-85/86

Free Speech, Free Sklyarov
Fight the unconstitutional DMCA.

Commander M

##### Share on other sites
grhodes_at_work: If b^2 - 4ac is negative, there are no real solutions. Or was that question intended from a programming perspective?

##### Share on other sites
quote:
Original post by Beer Hunter
grhodes_at_work: If b^2 - 4ac is negative, there are no real solutions. Or was that question intended from a programming perspective?

Your answer is basically what I was hoping to hear, although I was also wanting to point out that this situation is something to check for, at least during development and debugging.

There is another part to the question, something to think about not necessarily to answer. For the given equation, is there a physical interpretation of a non-real ("imaginary" or "complex") solution? I mean, you could plug in seemingly "legal" values for g, v, yi, and y that would result in an imaginary value for t:

v = 0 (object not currently moving)
g = 9.8 (yes, its gravity)
yi = 0 (object started at yi = 0)
y = 1 (object is currently at y = 1)

yields:

A = -9.8/2 = -4.9
B = 0
C = 0 - 1 = -1

So, b[sup]2[/sup]-4AC = 0*0 - 4*(-4.9)(-1) = -19.6

which requires we deal with sqrt(-19.6)

Is it *possible*, for the given equation, to have a situation that results in an imaginary time value? Are the example values above "legal"?

Please excuse me if that sounds like a math teacher equation. It really *is* one of those.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Edited by - grhodes_at_work on October 3, 2001 2:49:34 PM

##### Share on other sites
An object starts from rest at position = 0, and accelerates forwards at 2m/s. At what time will it be at position = -1?

##### Share on other sites
quote:
Original post by Beer Hunter
An object starts from rest at position = 0, and accelerates forwards at 2m/s. At what time will it be at position = -1?

Yes, exactly! The values I gave are not "legal" for the equation. They are not compatible with the assumptions used to derive the equation.

But if you''re simulating systems with oscillatory modes, such as systems with springs that have vibration modes, *then* complex/imaginary numbers do appear. They can be used to represent periodic solutions.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

##### Share on other sites
Which sort of systems? I''ve only looked at SHM and UCM in my physics class, and I don''t think you can get complex results with those, except for invalid cases. Or am I looking in the wrong place?

##### Share on other sites
quote:
Original post by Beer Hunter
Which sort of systems? I've only looked at SHM and UCM in my physics class, and I don't think you can get complex results with those, except for invalid cases. Or am I looking in the wrong place?

Actually, SHM (for example) *is* part of a complex result! Or at least complex variables can be used to achieve the equations for SHM. Its just rarely presented that way until you get into the theory of vibrations or control systems. But here is how it works.

The fundamental equation of motion is Newton's second law,

  F = m*a = m*(d2s/dt2)

Here, s is the displacement, and so acceleration a is the second derivative of displacement in time.

lets suppose that the force F is actually a spring force, which for a linear spring is defined as:

     F = -k*s

where k is the stiffness of the spring. And the spring force acts to restore displacement to zero. (I'm considering here a mass that oscillates about an initial position of s = 0, but the equation is similar for other systems.)

Then from Newton's law and the spring equation we can write the equation of motion for our mass and spring:

      -k*s = m*(d2s/dt2)

We'd like to solve for s. How do we do it, given that we have a derivative of s on one side and just s on the other side? When F was a constant m*g/2 we could just integrate twice to get an equation for s, and that's exactly how we get the quadratic equation form for s.

In this case, we can't simply integrate. We have to solve this ordinary differential equation some other way. And the way to do it is to assume a form for s. We're going to assume s is:

      s = A*exp(i*omega*t)

where A is an unknown constant, i is sqrt(-1), omega is an unknown constant, and t is time.

Now, there's magic in that exp(i*omega*t). From complex number theory, it is true that:

ds/dt = A*i*omega*exp(i*omega*t)andd2s/dt2 = A*i2*omega2*exp(i*omega*t)or, since i2 = -1,d2s/dt2 = -A*omega2*exp(i*omega*t)

And we can simply plug those into our equation of motion to get:

-k*A*exp(i*omega*t) = -m*A*omega2*exp(i*omega*t)

Now if you look at this you'll see that A*exp(i*omega*t) can be divided out to get:

-k = -m*omega2oromega = sqrt(k/m)

Then we know part of our solution s:

s = A*exp(i*sqrt(k/m)*t)

Now, there's still more magic in that exp() term. In complex number theory, it is true that:

exp(iX) = cos(X) + i*sin(X)

So the exponential of a complex number is equal to a complex harmonic function! And,

s = A*cos(omega*t) + i*A*sin(omega*t)

So omega turns out to be the frequency of oscillation, in radians/unit time.

*That* is the complex equation of harmonic motion for a mass connected to a spring. Note that A is determined by plugging in initial conditions (e.g., s = 0 when t = 0) and solving for A.

For determining the *real* position of the object s, you don't need the imaginary component. Just drop the imaginary component to get the SHM solution.

When combined with A, which can be complex, the imaginary component really models a time lag, for example, if you had two masses oscillating out-of-phase.

Note that if A = i, then the real part of s will have the sin() function instead of the cos() function.

So, that's way off topic but it actually is the starting point for understanding how to simulate more interesting systems. If you were to add in a damping force you could follow this same procedure, with just a slightly different assumed form for s. This kind of analysis becomes important when you are concerned about the stability of a simulation of, say, soft bodies.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Edited by - grhodes_at_work on October 5, 2001 4:51:04 PM

Edited by - grhodes_at_work on October 5, 2001 4:51:52 PM

##### Share on other sites
That... almost makes sense. The one thing that I don''t quite get is, why do we assume that:

s = A*exp(i*omega*t)

That sort of looks like we''re assuming that the answer will be in terms of sines or cosines...

##### Share on other sites
Hey Guys!!!! Thanks for all the discussion. I have another post I was hoping you could help me with titled "Need help with this vector problem".

##### Share on other sites
quote:
Original post by Beer Hunter
That... almost makes sense. The one thing that I don''t quite get is, why do we assume that:

s = A*exp(i*omega*t)

That sort of looks like we''re assuming that the answer will be in terms of sines or cosines...

There''s a reason why I assumed the complex form exp(i*omega*t) instead of just assuming it was a real-valued harmonic function directly. Read on.

That assumption is made by observation. Since the time derivatives of this form include the original function, just multiplied by coefficients, then we can divide out the original function and convert the ordinary differential equation into an algebraic equation, making it easy to solve for omega and A---really, making it easy to solve the ODE. Yes, exp(i*omega*t) is made of sines and cosines, and ultimately for displaying the simulation we''re only interested in the real part.

But it actually wouldn''t work in general to go ahead and assume the real-valued harmonic function instead of the exp form...

We could have achieved the same result for this problem just by assuming s = A*cos(omega*t + phi) instead. This works for our case since the equation of motion includes only s and the second time derivative of s. Since the second derivative of this new form includes cos(omega*t + phi), we can divide out the cos() to get an algebraic equation. But would that work if we also had a first derivative of s, ds/dt? (This would occur if we had damping.) No, since ds/dt would have sin(omega*t+phi) and so we can''t divide out the cosine or sine terms. But the exp() form would still work.

The moral of the prior paragraph is that the exp() form works for ODE''s that have any combination of odd and even time derivatives of the unknown variable, while making a direct assumption that s is written in terms of real-valued sine or cosine will only work if the ODE has all odd or all even time derivatives, but not both odd and even.

Does that help? Or maybe more confusing?

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

##### Share on other sites
I know that exp(i*theta) = cos(theta) + i sin(theta), that can be seen simply from the equations for exp, sin and cos. What I meant was, aren''t we assuming that one of the final equations for SHM will be in terms of sin or cos?

Still, you answered that, too. We need a second derivative equal to a multiple of the function, and exp makes sense there.

Thanks!

##### Share on other sites
Ok, this post is for graham rhodes (moderator):
I see that you have decided to close some threads that concerned homework problems. In my opinion, isn't it better to let him/she and everyone else that has problems with this stuff to post their questions and IF someone wants to answer they could do so?

I mean, if you and everyone else thinks it's a simple problem, then you don't have to reply, and thus leave the thread unanswered. If someone has the time and wants to answer they could do so and everyone is happy, especially the poster (aj37 in this case).

I don't know, but there might be a risk that the forum gets filled with such questions, but I don't think so.

Anyway, that's my humble opinion.

/Mankind gave birth to God.

Edited by - silvren on October 9, 2001 11:53:54 AM

##### Share on other sites
quote:
Original post by silvren
Ok, this post is for graham rhodes (moderator):
I see that you have decided to close some threads that concerned homework problems. In my opinion, isn''t it better to let him/she and everyone else that has problems with this stuff to post their questions and IF someone wants to answer they could do so?

I mean, if you and everyone else thinks it''s a simple problem, then you don''t have to reply, and thus leave the thread unanswered. If someone has the time and wants to answer they could do so and everyone is happy, especially the poster (aj37 in this case).

I don''t know, but there might be a risk that the forum gets filled with such questions, but I don''t think so.

Anyway, that''s my humble opinion.

I did consider that approach, and discussed different options with the other moderators on this board before deciding on the thread-closing approach. One certainly could argue that your approach is more appropriate than mine. The problem I personally have with just allowing people to choose to respond or not is that there will always be someone who will respond to simple questions, and that''s exactly what the poster is counting on. It is my opinion that in these cases the poster is cheating on an assignment, which leads a teacher to erroneously judge the forum''s comprehension of a technical subject, and not the student''s comprehension and problem-solving skills. Of course, there''s almost no chance in hell that the teacher will ever know that the student cheated in this way. Given that there are some lazy folks who will always try to cheat, I''ve closed some threads hoping to reduce the cheating that goes on here.

I personally believe it does the poster a disservice to give answers to questions that are clearly homework problems, as you''ve no doubt understood from my post to the closed threads.

Now, given all of that ...if the question were posted in the right way, and the poster was asking for hints, or just a different description of the problem, I could see that as a legitimate request. And I will consider this before closing future homeworky threads. And if I see that a person has asked for help on homework in the right way, I''ll post a reply to praise the person for that.

If a person is having trouble understanding a concept, its time for them to visit their teacher/professor or meet with other students in the same class. To merely ask for a solution here does not usually help the person to actually learn and understand the math. I would not feel the same way if the poster would show the work of their prior efforts in detail, then ask for hints of how to proceed. It is the asking for solutions that I feel is just wrong.

I do believe in helping people to solve problems that arise in (especially) game development. I participate in these forums, and moderate this forum, in an attempt to help people educate themselves and solve problems. The vast majority of the initial posts are either clearly related to game development or show that the poster has done significant work before making the post.

You may notice that I did not close this thread, since the simple problem in question does arise in implementing simple game physics.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

##### Share on other sites
well-spoken!

I can only agree.

/Mankind gave birth to God.

##### Share on other sites
Well Beer Hunter, the general solution of the differential equation (DE)
d2 x / dt2 = c2 * x

is
x = A * exp (c*t) + B * exp (-c*t)

It can be shown that the general solution of a homogeneous DE with constant coefficients is a linear combination of exponential functions. So the exponential function is a property of the equation.
The coefficients A and B follow from the boundary contitions.

Edited by - VolkerG on October 9, 2001 2:41:09 PM

##### Share on other sites
Come on, stop doing the kid''s homework for him. This is basic physics!

##### Share on other sites
I always *hated* the fact that you had to mystically divine the correct form of the answer to an ODE before you solved it - which is why I use Laplace transforms to solve them all (the only tricky part is factoring the transformation, and if you take some liberties with an arbitrary constant it gets really easy). i.e. You can use Laplace transforms to solve general ODE''s, not just ones with boundary conditions.

(And it has nothing to do with the fact that my TI-92 can be programming to do L{} & L-1{})

Magmai Kai Holmlor
- Not For Rent

##### Share on other sites
quote:
Original post by Omaha
Come on, stop doing the kid''s homework for him. This is basic physics!

The discussions have evolved beyond the homework question now, although I agree with the thought (obviously, ).

Offline, the other moderators and I have been discussing the issue of homework questions posted here, and how to deal with them. There''s no real way we can totally prevent people from cheating, but we can discourage it. And we can encourage other forum members to NOT help a person cheat.

I''ve created a Math & Physics forum FAQ with some guidance on the issue of homework, and you may want to read it. I have a feeling some of this guidance will be posted in a way that all forum members can easily see it in the near future.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

##### Share on other sites
quote:
Original post by Magmai Kai Holmlor
I always *hated* the fact that you had to mystically divine the correct form of the answer to an ODE before you solved it - which is why I use Laplace transforms to solve them all (the only tricky part is factoring the transformation, and if you take some liberties with an arbitrary constant it gets really easy).

For the problem we''re discussing, the assumed exponential form is directly related to the Laplace transform solution. Our assumed form produces the same algebraic characteristic equation as the Laplace transform.

Of course the Laplace transform is only useful for ODE''s that are LINEAR. And so you wouldn''t really use it to solve "general" ODE''s, . The problem actually might be MORE difficult! The full Newton-Euler equations of motion, for example, are NOT linear for general problems. Even a simple pendulum is not a linear problem (although the standard introductory physics textbook solution for pendulum motion is for a linearized version of the equation of motion....). Try to solve this using the Laplace transform:

J*d2theta/dt2 = -m*L*sin(theta)

This is basically the nonlinear equation of motion for an undamped simple pendulum with theta being the angle measured counterclockwise from straight down, bob mass of m, length L, and initial position at time 0 of theta(t=0) = 0.

You can do the Laplace transform of d2theta/dt2, but to transform sin(theta) you have to assume a form for theta! (There''s that "mystical divine" stuff again!) Otherwise, how can you do the Fourier integral:

L(sin(theta)) = integral_0_infinity(sin(theta)*exp(-st)*dt)

Even when you do assume a form----which will intuitively include a harmonic function----you''ll end up integrating something like sin(sin(omega*t)). Have you ever integrated the sine of a sine? If you manage to do this, chances are you''re not going to end up with an algebraic equation in the end, which is really the reason you wanted to use Laplace transform in the first place, . Food for thought.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

##### Share on other sites
Ok so it was a rash statement to say I can solve _all ODE's with laplace transforms - but I think I can solve that one.
I'm a little rusty on Laplacain/Holmlorain arbitration, but I'll try to remember:

J*d2theta/dt2 = -m*L*sin(theta)

Let y' '(t) = d2theta/dt2
L{y(t)} = Y(s)
L{y' '(t)} = s2*Y(s) - s*y'(0) - y(0)
(since y'(0) and y(0) are unknown, we will give them the distinct arbitrary constant values c1 and c2)

L{sin(t)} = k2 / (s2 + k2)
However, as you pointed out, the sin is problematic. Not entirely unlike taking a square root, taking the laplacain of a sin requires special attention - in particular, whenever you take the laplacain of a sin (or cos) you add the laplacain of cos (or sin) and multiple it by (yet another) arbitrary constant.
This may be mystical, but at least it's not divine. You do the same thing the same way every time, just like +/- the square root.

So, for our purposes:
L{sin(t)} -> k2 / (s2 + k2) + c3*s2 / (s2 + k2)

J*y' '(t) + m*L*sin(t) = 0
Take the Laplacain
J*Y*s2 + c1s + c2 + m*L/ (s2 + 1) + c3*s/ (s2 + 1) = 0

Now we need to get rid of that ugly s2, so multiple by 1/s2

J*Y + c1/s + c2/s2 + m*L/ (s2 * (s2 + 1)) + c3* / (s * (s2 + 1)) = 0

Expand
J*Y + c1/s + c2/s2 - m*L/(s2 + 1) + m*L/s2 - c3*s/(s2 + 1) + c3/s = 0

Now, we can elminate the c3/s and m*L/s2 terms because they are subsumed into c1/s and c2/s2 arbitrary terms

J*Y + c1/s + c2/s2 - m*L/(s2 + 1) - c3*s/(s2 + 1) = 0

Inverse Laplacain

J*y(t) + c1*t + c2*t2 - m*L*sin(t) + c3*cos(t) = 0

Given initial conditions you can solve for c1, c2, & c3 using some LA.

Now, I know your thinking that that looks like a pile more work than other methods - but you can teach a computer this method (like a TI-92 for instance).

Magmai Kai Holmlor
- Not For Rent

not much of a chance getting that right the first time

Edited by - Magmai Kai Holmlor on October 12, 2001 2:52:32 AM

##### Share on other sites
I should say first that there was an error in my equation. I neglected to include the gravitational acceleration, g in the right-hand-side. The equation should be:

J*d2theta/dt2 = -m*g*L*sin(theta)

If the mass is approximated as a point mass, then J = m*L*L, and the equation can be rewritten:

d2theta/dt2 = -(g/L)*sin(theta)

Otherwise, you have to keep J in there explicitly.

quote:
Original post by Magmai Kai Holmlor
L{sin(t)} = k2 / (s2 + k2)

Nice try, but there is fundamental flaw in your analysis, not to mention at least two errors. You're taking the Laplacian of sin(t), where t is time. Actually, looks like you meant to take the Laplacian of sin(k*t), not just sin(t). The k in the numerator should not be squared, thus the correct Laplacian of sin(k*t) is:

L{sin(k*t)} = k / (s2 + k2)

Likewise, the s in the numerator of L{cos(t)} should not be squared. The correct transform is:

L{cos(k*t)} = s / (s2 + k2)

[reference: "Introduction to Control System Analysis and Design" by Francis J. Hale, Prentice Hall, 1973, Chapter 2].

Probably a careless error, due to "rustiness," . But the erroneous square in the numerators is not the fundamental flaw of your analysis. The fundamental flaw is that you've transformed the wrong equation! You took my equation, shown below with your variable y(t) replacing my theta...

J*d2y(t)/dt2 = -m*g*L*sin(y(t))

...and transformed it into the following:

J*d2y(t)/dt2 = -m*g*L*sin(t)

Its not the same thing. Your replacement equation can be solved with Laplace transforms (as you well proved---apart from the minor error I pointed out). But you have not solved the actual equation of motion for a nonlinear simple pendulum. Or even a linear pendulum. The harmonic functions for y(t) for a linear pendulum should show a frequency that is a function of g and L, but your solution shows a frequence of exactly 1.0.

Tell me, what is the Laplace transform of sin(y(t))? Well, if you say that y(t) = t then the equation is your equation and it can be solved. But if y(t) = A*sin(constant*t+phi), which is required for the nonlinear pendulum in a simple constant gravity field, the Laplace transform is at least much more difficult, and there may be no closed form equation at all for the transform... There may be a way, but I don't think you'll find the answer in a simple table of Laplace transforms.

Anyway, this is all a bit overkill. For nonlinear problems that are interesting enough to put into games, we'd use numerical methods rather than sweat over trying to find a closed form solution. Still, its good to hone up on those old heavy math skills sometimes, .

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

______________________________
These superscripts are driving me crazy!

Edited by - grhodes_at_work on October 12, 2001 2:13:58 PM

Edited by - grhodes_at_work on October 12, 2001 2:14:55 PM