Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica Problem, please help me!

  1. Apr 28, 2008 #1
    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.

  2. jcsd
  3. Apr 28, 2008 #2
    Welcome to PF

    Write F[x_] instead.

    Code (Text):
    F[x_]:=y/.FindRoot[y/(Exp[y] -1) == Log[1+x]/x, {y, 1}];
    Last edited: Apr 28, 2008
  4. Apr 28, 2008 #3
    Ah, thank you so much, I really appreciate it.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?