# Find the function for a decision variable

**URL:** <https://community.wolfram.com/t/find-the-function-for-a-decision-variable/24175>\
**Category:** Questions\
**Tags:** operations-research, calculus, equation-solving, optimization, symbolic-computations\
**Created:** [July 3, 2024, 10:15pm UTC](https://community.wolfram.com/t/find-the-function-for-a-decision-variable/24175 "2024-07-03T22:15:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![icebearr54](https://avatars.discourse-cdn.com/v4/letter/i/ed655f/32.png) [@icebearr54](https://community.wolfram.com/u/icebearr54)\
**Post date:** [July 3, 2024, 10:15pm UTC](https://community.wolfram.com/t/find-the-function-for-a-decision-variable/24175/1 "2024-07-03T22:15:01Z")

</div>

Hi, I’m currently trying to find the equation for a decision variable from a total profit equation using Mathematica. From what I’ve read, I can use the solve function to do this. Here’s a example i found:

```
(*Define the total cost function*)
TC[Q_] := (D S/Q) + (H Q/2)

(*Compute the first derivative*)
dTCdQ = D[TC[Q], Q]

(*Solve for Q*)
solution = Solve[dTCdQ == 0, Q]

(*Simplify the solution*)
simplifiedSolution = Simplify[solution]

```

However, when I try to apply this to my actual equation, the program runs for hours without completing (it stuck). Here is my specific code:

```
TP[x_] = pr/x ((a (1 - b) (x^2))/(2 L) ((y g)/(1 + y g)))^(1/(
   1 - b)) - ((c + 1) (Kr/x + Kp/(n x) + Kf/(
      n x) + (hr + g)/
       x (2 x (-((a (-1 + b) g x^2 y)/(L + g L y)))^(1/(1 - b))) + (
       hp + g)/(2 R x) ((a (1 - b) (x^2))/(2 L) ((y g)/(1 + y g)))^(
       2/(1 - b)) + ((hp + g) (n - 1))/(
       2 x) ((a (1 - b) (x^2))/(2 L) ((y g)/(1 + y g)))^(2/(
       1 - b)) (x ((a (1 - b) (x^2))/(2 L) ((y g)/(1 + y g)))^(1/(
          1 - b)) - 1/R) + 
      1/x^2 S + (v/x + vp/(n x)) ((a (1 - b) (x^2))/(
         2 L) ((y g)/(1 + y g)))^(1/(1 - b)) + 
      1/(n x)^2 Sv + (Pv w)/( 
       x f ww) ((a (1 - b) (x^2))/(2 L) ((y g)/(1 + y g)))^(1/(
       1 - b)) + (((cf f) + (m bk))/( 
        x f ww ) {k n x + 
          k/q (Log[1 + z E^(-q n x)] - Log[1 + z])}) )) + (c ((pp/x + 
        pf/x) ((a (1 - b) (x^2))/(2 L) ((y g)/(1 + y g)))^(1/(
      1 - b)))) + (pr/x l (
     2 a g (x^2)
       y (((-((a (-1 + b) g x^2 y)/(L + g L y)))^(1/(1 - b)))^b) )/(
     L + g L y) - ((a (1 - b) (x^2))/(2 L) ((y g)/(1 + y g)))^(1/(
     1 - b)) (M - x))
(*Compute the first derivative*)
dTPdx = D[TP[x], x]

(*Solve for p*)
solution = Solve[dTPdx == 0, x]

(*Simplify the solution*)
simplifiedSolution = Simplify[solution]

```

Any suggestions on how to resolve this issue? Are there more efficient methods or best practices I should consider for solving complex equations in Mathematica?

[coba2.nb](https://community.wolfram.com/uploads/short-url/cYmrB1VQgRESuXDyBRP6b9E6HCw.nb) (40.5 KB)

---

<div class="post-metadata">

**Author:** ![mariuszi28cg](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mariuszi28cg/32/308_2.png) [@mariuszi28cg](https://community.wolfram.com/u/mariuszi28cg)\
**Post date:** [July 4, 2024, 7:33am UTC](https://community.wolfram.com/t/find-the-function-for-a-decision-variable/24175/2 "2024-07-04T07:33:31Z")

</div>

Given the state of today’s **mathematical knowledge** , the only way is to calculate it **numerically.**  
**Transcendental** [equation](https://en.wikipedia.org/wiki/Transcendental_equation) **can’t** be solved **analytically.**

If **Mathematics** can’t do then **Mathematica** either.

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/3a57da91-0400-4cb0-a203-49b07a96cc82)

Regards M.I.

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [July 4, 2024, 9:12am UTC](https://community.wolfram.com/t/find-the-function-for-a-decision-variable/24175/3 "2024-07-04T09:12:55Z")

</div>

Depending on the parameters, your equation has a variable number of solutions:

```
TP[x_] = 
 pr/x ((a (1 - b) (x^2))/(2 L) ((y g)/(1 + y g)))^(1/(1 - 
         b)) - ((c + 1) (Kr/x + Kp/(n x) + 
       Kf/(n x) + (hr + g)/
         x (2 x (-((a (-1 + b) g x^2 y)/(L + g L y)))^(1/(1 -
                b))) + (hp + 
           g)/(2 R x) ((a (1 - b) (x^2))/(2 L) ((y g)/(1 + 
               y g)))^(2/(1 - b)) + ((hp + g) (n - 
             1))/(2 x) ((a (1 - b) (x^2))/(2 L) ((y g)/(1 + 
               y g)))^(2/(1 - 
             b)) (x ((a (1 - b) (x^2))/(2 L) ((y g)/(1 + 
                  y g)))^(1/(1 - b)) - 1/R) + 
       1/x^2 S + (v/x + 
          vp/(n x)) ((a (1 - b) (x^2))/(2 L) ((y g)/(1 + 
               y g)))^(1/(1 - b)) + 
       1/(n x)^2 Sv + (Pv w)/(x f ww) ((a (1 - 
                b) (x^2))/(2 L) ((y g)/(1 + y g)))^(1/(1 - 
             b)) + (((cf f) + (m bk))/(x f ww) (k n x + 
           k/q (Log[1 + z E^(-q n x)] - 
              Log[1 + z]))))) + (c ((pp/x + 
         pf/x) ((a (1 - b) (x^2))/(2 L) ((y g)/(1 + 
              y g)))^(1/(1 - b)))) + (pr/
       x l (2 a g (x^2) y (((-((a (-1 + b) g x^2 y)/(L + 
                   g L y)))^(1/(1 - b)))^b))/(L + 
         g L y) - ((a (1 - b) (x^2))/(2 L) ((y g)/(1 + 
             y g)))^(1/(1 - b)) (M - x)) // Simplify
(*Compute the first derivative*)
dTPdx = D[TP[x], x] // Simplify;
effe = Block[{a = 1, b = 2, bk = 1, c = 1, cf = 4, f = 1, g = 1, 
   hp = 1, hr = 1, k = 1, Kf = 1, Kp = 1, Kr = 1, l = 1, L = 1, m = 1,
    M = 1, n = 1, pf = 1, pp = 1, pr = 1, Pv = 1, q = 1, R = 1, S = 1,
    Sv = 1, v = 1, vp = 1, w = 1, ww = 1, y = 1, z = 1},
  dTPdx]
Plot[effe, {x, -10, 10}, PlotRange -> {-1, 1}]
Solve[effe == 0, x, Reals]
gi = Block[{a = 1, b = 0, bk = 1, c = 1, cf = 4, f = 1, g = 1, hp = 1,
    hr = 1, k = 1, Kf = 1, Kp = 1, Kr = 1, l = 1, L = 1, m = 1, M = 1,
    n = 1, pf = 1, pp = 1, pr = 1, Pv = 1, q = 1, R = 1, S = 1, 
   Sv = 1, v = 1, vp = 1, w = 1, ww = 1, y = 1, z = 1},
  dTPdx]
Plot[gi, {x, -10, 10}, PlotRange -> {-1, 1}]
Solve[gi == 0, x, Reals]
acca = Block[{a = 4, b = 2, bk = 1, c = 1, cf = 4, f = 3, g = 2, 
   hp = 1, hr = 1, k = 1, Kf = 2, Kp = 1, Kr = 5, l = 3, L = 1, m = 1,
    M = 1, n = 1, pf = 4, pp = 1, pr = 1, Pv = 1, q = 1, R = 10, 
   S = 1, Sv = 1, v = 1, vp = 1, w = 1, ww = 1, y = 1, z = 2},
  dTPdx]
Plot[acca, {x, -10, 10}]
Solve[acca == 0, x, Reals]

```

You cannot expect a simple analytical solution for the general case.
