Solving Mathematica Problems with FindRoot - Claire

  • Mathematica
  • Thread starter babygrace9
  • Start date
  • Tags
    Mathematica
In summary, Claire has been struggling with a problem in Mathematica for about a week. She needs a function, F[x], that can take any value of x and use FindRoot to find the corresponding value of y. She has tried several equations but they only work if x is already assigned a numerical value. She is looking for advice on how to create this function.
  • #1
babygrace9
2
0
I've been having this problem for about a week now, and would love to hear from anyone who is familiar with Mathematica and can offer some insight:

I think the basic concept is simple. I have two variables, let's call them x and y, related in the following way:
y/(Exp[y] -1) = Log[1+x]/x

I know the value of x, and I would like to know the value of y. Thus I can employ FindRoot:
FindRoot[y/(Exp[y] -1) == Log[1+x]/x, {y, 1}]

If I have specified the value of x already, i get a good response from FindRoot, for example
In: x = -.6
FindRoot[y/(Exp[y] -1) == Log[1+x]/x, {y, 1}]
Out: {y -> -.916291}

However, what I really want is a function called F[x], such that when I feed any value of x to it, it will apply FindRoot and give the numerical value of y. I have tried the following equation:

F[x] := FindRoot[y/(Exp[y] -1) == Log[1+x]/x, {y, 1}]

and the equation
F[x] := x /. FindRoot[y/(Exp[y] -1) == Log[1+x]/x, {y, 1}]

and also the equation
F[x] /. FindRoot[y/(Exp[y] -1) == Log[1+x]/x, {y, 1}]

All of these give me an error, unless I have "preassigned" a numerical value of x. But I don't want to have a preassigned value of x, I want to be able to enter any value of x that I choose into F[x] and have FindRoot spit out a numerical value for y. Is this possible? Can anyone better at Mathematica than I am give me some advice? I would be forever in your debt, this has been driving me crazy.

Thanks,
Claire
 
Physics news on Phys.org
  • #2
Welcome to PF

Write F[x_] instead.


Code:
F[x_]:=y/.FindRoot[y/(Exp[y] -1) == Log[1+x]/x, {y, 1}];
 
Last edited:
  • #3
Ah, thank you so much, I really appreciate it.
 

1. How does FindRoot work in Mathematica?

FindRoot is a built-in function in Mathematica that uses numerical methods to solve equations. It takes in an equation or set of equations and an initial guess for the variables, and then iteratively refines the value of the variables until the solution is found.

2. Can FindRoot handle complex equations?

Yes, FindRoot can handle complex equations as long as they can be expressed numerically. However, the initial guess for the variables must also be complex numbers.

3. What happens if FindRoot fails to find a solution?

If FindRoot fails to find a solution, it will return an error message indicating that it could not converge to a solution. This can happen if the initial guess is too far from the actual solution or if the equation is too complex for the numerical methods used by FindRoot.

4. How can I improve the accuracy of FindRoot?

You can improve the accuracy of FindRoot by adjusting the options of the function. The default options may not be suitable for all equations, so it is recommended to experiment with different options such as the maximum number of iterations or the precision of the solution.

5. Are there any alternatives to FindRoot in Mathematica?

Yes, there are other functions in Mathematica that can solve equations, such as NSolve and Reduce. These functions use different methods and may be more suitable for certain types of equations. It is recommended to try different functions to find the best solution for your specific problem.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
868
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
Back
Top