Message Boards Message Boards

0
|
3075 Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:

Rootfinding

Posted 10 years ago

As I am starting to use Mathematica, I would like to share with you a problem.

I have tried to solve an equation by using FindRoot but I get a very strange message.

I don't understand why Mathematica is not able to return the parameter value, because if I replace the parameter by its value, Mathematica is able to give the equation solution.

FindRoot is unable to solve for Y

FindRoot[(1 - (4/y)(((1/y)Integrate[x /(E^x - 1), {x, 0, y}] + y/2) - 1)) == 0.395544 , {y, -4.1}]

But if we replace Y with the correct value, we get the equation solution: 0.395544

(1 - (4/-4.1)(((1/-4.1)Integrate[x /(E^x - 1), {x, 0, -4.1}] + -4.1/ 2) - 1))

Attachments:
POSTED BY: Derek Tom

From the documentation for FindRoot:

FindRoot first localizes the values of all variables, then evaluates f with the variables being symbolic, and then repeatedly evaluates the result numerically.

So your warning message is because of this.

If you define

g[y_?NumericQ] := 
 1 - (4 ((Integrate[x/(E^x - 1), {x, 0, y}]/y + y/2) - 1))/y

(which causes FindRoot to skip the symbolic evaluation) and then evaluate

FindRoot[g[y] == 0.395544, {y, -4.}]

You get the desired answer. Buyt also note that the integration can be done analytically:

In[41]:= 1 - (4 ((Integrate[x/(E^x - 1), {x, 0, y}]/y + y/2) - 1))/y

Out[41]= ConditionalExpression[
 1 - (4 (-1 + y/
     2 + (-(\[Pi]^2/6) - y^2/2 + y Log[1 - E^y] + PolyLog[2, E^y])/
     y))/y, E^y <= 1]

So why not use that so that the integration does not need to be done repeatedly. Note the ConditionalExpression (which is the root cause of your problem) so you need to strip the function of this and just be sure that your domain of root finding is consistent with the constraints of the ConditionalExpression. E.g.:

FindRoot[1 - (
   4 (-1 + y/
      2 + (-(\[Pi]^2/6) - y^2/2 + y Log[1 - E^y] + PolyLog[2, E^y])/
      y))/y == 0.395544`, {y, -1.}]
POSTED BY: David Reiss
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