0
$\begingroup$

I have developed a program that solves an equation and give its solutions as outputs:

m = 0.3
n = -0.9
equation = Reduce[E^(m*x) + E^(n* x) == x, x, Reals]
sol1 = N[x /. ToRules[equation[[1]]]]
sol2 = N[x /. ToRules[equation[[2]]]]

whose answers are approximately 1.97121 and 5.93163. However, I need m to change and, therefore, to render a different solution each time I change it. So I need m to be also 0.05, 0.06, 0.1,… and whatever numbers I define in a list. How can I arrange Reduce to read the different values and to solve the equation for each of them, given a list of values for m?

$\endgroup$

1 Answer 1

2
$\begingroup$
Clear["Global`*"]

n = -9/10;

sol[m_?NumericQ] := NSolve[{E^(m*x) + E^(n*x) == x, x > 0}, x, Reals]

sol[0.3]

(* {{x -> 1.97921}, {x -> 5.93163}} *)

data = Select[Table[{m, x /. sol[m]}, {m, 0.01, 0.5, 0.01}], 
   UnsameQ[#[[2]], x] &];

ListLogPlot[data[[All, 2]] // Transpose,
 DataRange -> MinMax[data[[All, 1]]],
 Joined -> True]

enter image description here

EDIT: Using bisection to find where the curves intersect:

lb = 0.35`20; ub = 0.36`20;

While[ub - lb > 10^-12,
 a = (lb + ub)/2;
 If[sol[a] === {}, ub = a, lb = a]]

{lb, sol[lb]} // N

(* {0.358662, {{x -> 3.01982}, {x -> 3.01982}}} *)
$\endgroup$
1
  • $\begingroup$ Absolutely FLAWLESS, dear Bob. Thank you for your support. You’re what I would call a ‘fluent speaker’ of Mathematica, even a native one, ha ha: those were some fancy Mathematica functions I didn’t know they existed, like NumericQ. I still have lots to learn. I still cannot cast my vote since my reputation ask for a couple of more points, but people seeing this comment may know this code works appropriately without a shadow of a doubt. $\endgroup$
    – mov0021
    Commented May 4, 2021 at 2:54

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.