3
$\begingroup$

I have this expression:

$d=-\frac{\sqrt{\frac{780 (f+130) \left(5 d^2 (13 c+f+130)-5 d (c (f+1300)-325 (f+160))+125 \left(2 (2 c+725) f+5 f^2+104000\right)+13 d^3\right) \left(5 d^2 (52 c+17 f+2600)+5 d \left(c (61 f+5200)+5 \left(f^2+290 f+20800\right)\right)-25 c f (f+80)+52 d^3\right) \left(300 c^2 (13 d-f)+5 c \left(208 d^2+d (121 f-2600)-5 \left(f^2+1280 f+156000\right)\right)+d \left(52 d^2+5 d (17 f+2600)+25 \left(f^2+290 f+20800\right)\right)\right)}{\left(5 d (13 c+f-130)-5 ((c+100) f+13000)+13 d^2\right)^3}+\left(-\frac{13 \left(5 d^2 (52 c+17 f+2600)+5 d \left(c (61 f+5200)+5 \left(f^2+290 f+20800\right)\right)-25 c f (f+80)+52 d^3\right)^2}{4 \left(5 d (13 c+f-130)-5 ((c+100) f+13000)+13 d^2\right)^2}+\frac{(25 (5 f+728)-780 c) \left(5 d^2 (52 c+17 f+2600)+5 d \left(c (61 f+5200)+5 \left(f^2+290 f+20800\right)\right)-25 c f (f+80)+52 d^3\right)}{4 \left(5 d (13 c+f-130)-5 ((c+100) f+13000)+13 d^2\right)}+975 c (f+80)\right)^2}+\frac{13 \left(5 d^2 (52 c+17 f+2600)+5 d \left(c (61 f+5200)+5 \left(f^2+290 f+20800\right)\right)-25 c f (f+80)+52 d^3\right)^2}{4 \left(5 d (13 c+f-130)-5 ((c+100) f+13000)+13 d^2\right)^2}+\frac{195 c \left(5 d^2 (52 c+17 f+2600)+5 d \left(c (61 f+5200)+5 \left(f^2+290 f+20800\right)\right)-25 c f (f+80)+52 d^3\right)}{5 d (13 c+f-130)-5 ((c+100) f+13000)+13 d^2}-\frac{125 f \left(5 d^2 (52 c+17 f+2600)+5 d \left(c (61 f+5200)+5 \left(f^2+290 f+20800\right)\right)-25 c f (f+80)+52 d^3\right)}{4 \left(5 d (13 c+f-130)-5 ((c+100) f+13000)+13 d^2\right)}-\frac{4550 \left(5 d^2 (52 c+17 f+2600)+5 d \left(c (61 f+5200)+5 \left(f^2+290 f+20800\right)\right)-25 c f (f+80)+52 d^3\right)}{5 d (13 c+f-130)-5 ((c+100) f+13000)+13 d^2}-975 c f-78000 c}{104 \left(-\frac{5 d^2 (52 c+17 f+2600)+5 d \left(c (61 f+5200)+5 \left(f^2+290 f+20800\right)\right)-25 c f (f+80)+52 d^3}{4 \left(5 d (13 c+f-130)-5 ((c+100) f+13000)+13 d^2\right)}-15 c\right)}$

The raw mathematica input for this is:

func = -(((13*(52*d^3 + 5*(52*c + 17*f + 2600)*d^2 + 5*(c*(61*f + 5200) + 5*(f^2 + 290*f + 20800))*d - 25*c*f*(f + 80))^2)/
  (4*(13*d^2 + 5*(13*c + f - 130)*d - 5*((c + 100)*f + 13000))^2) + 
 (195*c*(52*d^3 + 5*(52*c + 17*f + 2600)*d^2 + 5*(c*(61*f + 5200) + 5*(f^2 + 290*f + 20800))*d - 25*c*f*(f + 80)))/
  (13*d^2 + 5*(13*c + f - 130)*d - 5*((c + 100)*f + 13000)) - 
 (4550*(52*d^3 + 5*(52*c + 17*f + 2600)*d^2 + 5*(c*(61*f + 5200) + 5*(f^2 + 290*f + 20800))*d - 25*c*f*(f + 80)))/
  (13*d^2 + 5*(13*c + f - 130)*d - 5*((c + 100)*f + 13000)) - 
 (125*f*(52*d^3 + 5*(52*c + 17*f + 2600)*d^2 + 5*(c*(61*f + 5200) + 5*(f^2 + 290*f + 20800))*d - 25*c*f*(f + 80)))/
  (4*(13*d^2 + 5*(13*c + f - 130)*d - 5*((c + 100)*f + 13000))) - 78000*c - 975*c*f + 
 Sqrt[(-((13*(52*d^3 + 5*(52*c + 17*f + 2600)*d^2 + 5*(c*(61*f + 5200) + 5*(f^2 + 290*f + 20800))*d - 25*c*f*(f + 80))^2)/
       (4*(13*d^2 + 5*(13*c + f - 130)*d - 5*((c + 100)*f + 13000))^2)) + ((25*(5*f + 728) - 780*c)*(52*d^3 + 5*(52*c + 17*f + 2600)*d^2 + 
        5*(c*(61*f + 5200) + 5*(f^2 + 290*f + 20800))*d - 25*c*f*(f + 80)))/(4*(13*d^2 + 5*(13*c + f - 130)*d - 5*((c + 100)*f + 13000))) + 
     975*c*(f + 80))^2 + (780*(f + 130)*(13*d^3 + 5*(13*c + f + 130)*d^2 - 5*(c*(f + 1300) - 325*(f + 160))*d + 
      125*(5*f^2 + 2*(2*c + 725)*f + 104000))*(52*d^3 + 5*(52*c + 17*f + 2600)*d^2 + 5*(c*(61*f + 5200) + 5*(f^2 + 290*f + 20800))*d - 
      25*c*f*(f + 80))*(300*(13*d - f)*c^2 + 5*(208*d^2 + (121*f - 2600)*d - 5*(f^2 + 1280*f + 156000))*c + 
      d*(52*d^2 + 5*(17*f + 2600)*d + 25*(f^2 + 290*f + 20800))))/(13*d^2 + 5*(13*c + f - 130)*d - 5*((c + 100)*f + 13000))^3])/
(104*(-15*c - (52*d^3 + 5*(52*c + 17*f + 2600)*d^2 + 5*(c*(61*f + 5200) + 5*(f^2 + 290*f + 20800))*d - 25*c*f*(f + 80))/
   (4*(13*d^2 + 5*(13*c + f - 130)*d - 5*((c + 100)*f + 13000))))))

I want to solve for $func=d$ for real solutions. I'm using

Solve[func==d, d, Reals]

It seems to run for ages - will it complete? Is this the way I should be doing it?

$\endgroup$
4
  • 1
    $\begingroup$ If this takes too long, maybe you should consider whether you really need the analytic solution. Depending on what you do, it may be sufficient to find solutions for given numeric values of $f$ and $c$ (in which case you can wait with Solve until you have inserted those values, thus giving a much simpler expression to solve). You might even not need the complete set of solutions, in which case you may consider using FindInstance after inserting values. $\endgroup$
    – celtschk
    Commented Apr 13, 2014 at 16:25
  • $\begingroup$ I would prefer the analytic solution as it will eventually be put in a different executable. I am coming to the realisation that I will have to solve it numerically by calling out to mathematica's NSolve from C++ $\endgroup$
    – RNs_Ghost
    Commented Apr 13, 2014 at 16:56
  • 1
    $\begingroup$ Well, I managed to get a result by rewriting the equation to get rid of the square root. The results are in terms of Root objects and ConditionalExpressions and take many tens of pages. That won't do you any good. $\endgroup$ Commented Apr 13, 2014 at 17:24
  • $\begingroup$ Thanks for the effort @SjoerdC.deVries. The Numerical Solution is fast so I will just call out to mathematica from C $\endgroup$
    – RNs_Ghost
    Commented Apr 13, 2014 at 17:30

1 Answer 1

2
$\begingroup$

You can get an approximate analytical solution within a domain of other parameters using numerical solution. First get an idea of the nature of your function.

Plot[{func /. {c -> 1.5, f -> 1.5}, d}, {d, -1000, 1000}]

enter image description here

I can see there are two solutions - near 0 and near -500.

FindRoot[Block[{c = 1.5, f = 1.5}, func] == d, {d, 0}]
FindRoot[Block[{c = 1.5, f = 1.5}, func] == d, {d, -500}]

{d -> 0.00831943}

{d -> -375.409}

Let's focus on the solutions near 0.

data = Flatten[Table[{c, f, d /. FindRoot[func - d, {d, 0.01}]}
                   , {c, 0.1,  2, .1}, {f, 0.1, 2, .1}], 1];
ListPlot3D[data]
func1[x_, y_] = Interpolation[data][x, y]

enter image description here

and func1[x,y] is your approximate solution within the domain.

$\endgroup$

Your Answer

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

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