Message Boards Message Boards

0
|
5012 Views
|
3 Replies
|
6 Total Likes
View groups...
Share
Share this post:

[?] Solve an equation with a constraint?

Posted 5 years ago

Consider the following code:

Clear["Global`*"]
            h[e_, u_] := (e + u) Log[
                 u/(e + u)] + (1 - e - u) Log[(1 - u)/(1 - e - u)];
            Y = 10000000;
            t = {0.10, 0.15, 0.16};
            a = 0.05;
            n = 56;
            NSolve[Exp[n*h[u - Total[t]/n, 1 - u]] == a/2 && 1 >= u >= 0, u]
            NSolve[Exp[n*h[u - Total[t]/n, 1 - u]] == a/2 && 1 >= u >= 0.01, u]

Hello The first one with NSolve works and gives that answer

{{u -> 3.34543*10^-7}, {u -> 0.0879319}}

But the second dosent

{}

What's is the problem with the second one if I want to get one root that satisfies 1 >= u >= 0.01?

POSTED BY: Alex Graham
3 Replies

Change 0.01 to exact value 1/100.

$Version
(* 12.0.0 for Microsoft Windows (64-bit) (April 6, 2019) *)

NSolve[Exp[n*h[u - Total[t]/n, 1 - u]] == a/2 && 1 >= u >= 1/100, u]
(* {{u -> 0.0879319}} *)
POSTED BY: Mariusz Iwaniuk

Other ways around the problem:

NSolve[Exp[n*h[u - Total[t]/n, 1 - u]] == a/2 && .1 >= u >= 0.01, u]
Solve[Exp[n*h[u - Total[t]/n, 1 - u]] == a/2 && 1 >= u >= 0.01, u]
POSTED BY: Gianluca Gorni
Posted 5 years ago

From the documentation: "NSolve deals primarily with linear and polynomial equations."

But you can use FindRoot:

eq = Exp[n*h[u - Total[t]/n, 1 - u]] == a/2;
u /. FindRoot[eq, {u, .08}]

(* 0.0879318507538185` *)
POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract