1
$\begingroup$

I'm trying to solve quite a large equation for $x_2$ and for some reason Mathematica can't handle it. I'm not good enough at math to know why. I have a quadratic equation $f(x)=ax^2 + bx + c$, a point on the curve $(x_1, y_1)$, and a distance $L$. The length of a curve between 2 points given by:

Integrate[Sqrt[1 + (b + 2*a*x)^2], x]

this gives me:

-((ArcSinh[b + 2*a*Subscript[x, 1]] + (b + 2*a*Subscript[x, 1]) * 
Sqrt[1 + b^2 + 4*a*b*Subscript[x, 1] + 4*a^2*Subscript[x, 1]^2])/(4*a)) +
(ArcSinh[b + 2*a*Subscript[x, 2]] + (b + 2*a*Subscript[x, 2]) * 
Sqrt[1 + b^2 + 4*a*b*Subscript[x, 2] + 4*a^2*Subscript[x, 2]^2])/(4*a) == L

Given L and x_1, I need to figure out x_2. Or rather, I need to put x_2 in terms of {L, x_1, a, b}.

I'm pretty sure this is possible? If it isn't, I'd like to understand why. Here's my faulty code (it's big). Mathematica just responds with:

"Solve::nsmet: This system cannot be solved with the methods available to Solve."

Solve[FullSimplify[TrigToExp[-((ArcSinh[b + 2*a*Subscript[x, 1]] +
(b + 2*a*Subscript[x, 1]) * Sqrt[1 + b^2 + 4*a*b*Subscript[x, 1] +
4*a^2*Subscript[x, 1]^2])/(4*a)) + (ArcSinh[b + 2*a*Subscript[x, 2]] +
 (b + 2*a*Subscript[x, 2]) * Sqrt[1 + b^2 + 4*a*b*Subscript[x, 2] +
  4*a^2*Subscript[x, 2]^2])/(4*a) == L]], Subscript[x, 2]]/. Rule -> Equal

Update

So @Jack LaVigne's answer is probably the best way to handle this within Mathematica. However, my goal in all this was to find a solution that I could translate into traditional computer-language code for a dynamic quadratic equation defined by the (variable) coefficients ${a, b, c}$, a variable known length $L$, and an x-coordinate for a known point which I call $u$.

I found that the easiest way to get this into something I could translate into general-purpose computer code was using newtonian approximation. I made a very detailed step-by-step derivation of the solution in Mathematica:

https://drive.google.com/open?id=0B9YYph2TpOvrTVJ4aGFmMGxwVkU

Here is the Javascript code:

https://gist.github.com/sikanrong/bd7b05b800a5086c1502e2c7033127ed

You just pass in all the knowns, and it will run newton until it converges, and returns your answer, which is the x-coordinate for the unknown point which is a distance L along the curve away from the point at x-coordinate $u$.

I hope this helps people in the same situation.

$\endgroup$
  • $\begingroup$ no way you will get an analytic solution to that. You will need to specify all the parameters numerically and use NSolve or FindRoot $\endgroup$ – george2079 Jun 6 '17 at 21:32
  • $\begingroup$ Re-write your integral equation using the markup that you used for the output. $\endgroup$ – Jack LaVigne Jun 6 '17 at 22:12
  • $\begingroup$ This is another post about doing what I'm trying to do, but it has LaTeX formatting and everything is MUCH clearer... math.stackexchange.com/questions/2312754/… $\endgroup$ – Alex Pilafian Jun 6 '17 at 22:35
  • $\begingroup$ @JackLaVigne done $\endgroup$ – Alex Pilafian Jun 6 '17 at 22:41
2
$\begingroup$

Update

With the corrected integration equations

Assuming[Element[a | b | x1 | x2, Reals],
 Integrate[Sqrt[1 + (2 a x + b)^2], {x, x1, x2}]
]

(* ConditionalExpression[(1/(
 4 a))(-b Sqrt[1 + (b + 2 a x1)^2] - 2 a x1 Sqrt[1 + (b + 2 a x1)^2] +
    b Sqrt[1 + (b + 2 a x2)^2] + 2 a x2 Sqrt[1 + (b + 2 a x2)^2] - 
   ArcSinh[b + 2 a x1] + ArcSinh[b + 2 a x2]), x1 < x2] *)

Define a function to create the forward model for l given the other inputs:

lfun[a_, b_, x1_, x2_] := 
 1/(4 a) (-b Sqrt[1 + (b + 2 a x1)^2] - 
    2 a x1 Sqrt[1 + (b + 2 a x1)^2] + b Sqrt[1 + (b + 2 a x2)^2] + 
    2 a x2 Sqrt[1 + (b + 2 a x2)^2] - ArcSinh[b + 2 a x1] + 
    ArcSinh[b + 2 a x2])

Compute a test example

lfun[1, 2, 1, 2] // N

(* 5.1003 *)

Use FindMinimum to compute x2 assuming the other inputs are known:

With[
 {
  a = 1,
  b = 2,
  x1 = 1,
  l = 5.1003
  },
 FindMinimum[(l - lfun[a, b, x1, x2])^2, x2]
 ]

(* {1.76173*10^-20, {x2 -> 2.}} *)
$\endgroup$
  • $\begingroup$ Sorry I messed up on the first post. your integral should have been: Integrate[Sqrt[1 + (b + 2 a x)^2], {x, x1, x2}] $\endgroup$ – Alex Pilafian Jun 6 '17 at 22:33
  • $\begingroup$ @AlexPilafian Updated answer with your corrected equation. $\endgroup$ – Jack LaVigne Jun 7 '17 at 0:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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