0
$\begingroup$

I have the following code in Mathematica that represents two balls being thrown, one with a velocity v10 (6 in this case) and another ball thrown with a velocity v20 (its just dropped) one second later:

v10 = 6    
v20 = 0
a = -9.8
t0 = 0

v1[t_] = Integrate[a, t] + v10
v2[t_] = Integrate[a, t] + v20
x1[t_] = Integrate[v1[t], t] + h
x2[t_] = Integrate[v2[t], t] + h

eq1 = (t /. Solve[0 == x2[t], t]) + 1
eq2 = t /. Solve[0 == x1[t], t]

eq4 = Solve[eq1[[2]] == eq2[[2]]]

{{h -> 0.410596}}

h is the height the balls begin at in order to meet the ground at the same time. All is good. But as soon as I plug in a variable, V, for the velocity v10 everything falls apart:

v10 = V    
v20 = 0
a = -9.8
t0 = 0

v1[t_] = Integrate[a, t] + v10
v2[t_] = Integrate[a, t] + v20
x1[t_] = Integrate[v1[t], t] + h
x2[t_] = Integrate[v2[t], t] + h

eq1 = (t /. Solve[0 == x2[t], t]) + 1
eq2 = t /. Solve[0 == x1[t], t]

eq4 = Solve[eq1[[2]] == eq2[[2]]]

{h -> 1.61298*10^-61 (5.40298*10^92 - 1.10265*10^92 V + 5.62576*10^90 V^2 - 1. (-2.32443*10^46 + 2.37187*10^45 V) Sqrt[ 5.40298*10^92 - 1.10265*10^92 V + 5.62576*10^90 V^2])}, {h -> 1.61298*10^-61 (5.40298*10^92 - 1.10265*10^92 V + 5.62576*10^90 V^2 + (-2.32443*10^46 + 2.37187*10^45 V) Sqrt[ 5.40298*10^92 - 1.10265*10^92 V + 5.62576*10^90 V^2])}

Then if I go further and try to plug 6 back into the equation for V:

x[V_] = h /. eq4[[1]]
x[6]

2.62065*10^31

This is obviously the wrong answer. Am I missing something here?

$\endgroup$
4
  • 1
    $\begingroup$ I cannot replicate the indicated results. I guess some input is missing. By eyeball I do not see 'V' anywhere, for example. $\endgroup$ Jan 22, 2015 at 0:45
  • $\begingroup$ You're right, Daniel. It had a typo. It should work now. $\endgroup$
    – Mardymar
    Jan 22, 2015 at 0:54
  • $\begingroup$ Still nope, I think the problem is Solve[x10 == x2[t], t]. Note the undefined variable x10. $\endgroup$ Jan 22, 2015 at 0:55
  • 1
    $\begingroup$ I thought I got rid of that variable. I had two edits - now it should work. $\endgroup$
    – Mardymar
    Jan 22, 2015 at 0:58

1 Answer 1

4
$\begingroup$

You've encountered floating-point roundoff error. Note the combination of very large and very small numbers in eq4.

Let's try something different. I'll evaluate just your integrals, without the numbers:

v1[t_] = Integrate[a, t] + v10
v2[t_] = Integrate[a, t] + v20
x1[t_] = Integrate[v1[t], t] + h
x2[t_] = Integrate[v2[t], t] + h

Now we'll just Solve for t and h.

FullSimplify@Solve[x1[t] == 0 && x2[t-t0] == 0, {h, t}]

{{h -> -((t0 (a t0 + 2 v10) (a t0 - 2 v20) (a t0 + 2 v10 - 2 v20))/( 8 (a t0 + v10 - v20)^2)), t -> (t0 (a t0 - 2 v20))/(2 (a t0 + v10 - v20))}}

Now let's simply substitute our values:

% /. {v10 -> 6, v20 -> 0, a -> -9.8, t0 -> 1}

{{h -> 0.410596, t -> 1.28947}}

I've noticed that Mathematica often has trouble dealing with mixed symbolic/machine-precision expression. It was your intermediate Solve that gave it difficulty.

I almost always evaluate symbolically first. If your equation has no analytical solution, substitute your numbers as the last step before Solve.

$\endgroup$
3
  • $\begingroup$ I would also suggest using DSolve instead of Integrate, it will let you handle more complex cases easily. $\endgroup$ Jan 22, 2015 at 1:30
  • $\begingroup$ Thanks for the help. I had to use my original equations since your FullSimplify line didn't work for me (I got h->0, t->0), but substituting the numbers at the end worked like a charm. $\endgroup$
    – Mardymar
    Jan 22, 2015 at 2:29
  • $\begingroup$ @Mardymar Oops, the reason you got {h->0,t->0} was that I forgot the time offset. Check the Solve again now. $\endgroup$ Jan 22, 2015 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.