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

To solve an equation numerically using mathematica.

  1. Mar 18, 2009 #1


    User Avatar
    Gold Member

    Hi, at the moment I'm trying to find how to solve numerically an equation, for Saha equation, when the ratio is 1, to extract T.
    Any command line which can do the job?
    I guess something in the line of solvefor[T] or something like this, I'm using mathematica 7.0.

  2. jcsd
  3. Mar 18, 2009 #2


    User Avatar
    Science Advisor
    Homework Helper

    I don't know precisely what your equation is, but usually NSolve will do. It works just like Solve:
    NSolve[x^2 - 1, x]

    Sometimes NSolve gets really confused and you can resort to even "more numerical" methods using FindRoot, for which you will have to give an estimate of the solution in the argument, e.g.
    FindRoot[x^2 == 1, {x, 2}]
    will find x = 1 as root, and
    FindRoot[x^2 == 1, {x, -0.1}]
    will find x = -1 as root.
    If your guess is "unlucky" you might find neither, e.g.
    FindRoot[x^2 == 1, {x, 0}]
    will produce an error (if you know Newton's method for finding zeroes of a function, you see why :smile:)

    (note that you can use either the form a == b, or the form z which is equivalent to z == 0 in both commands).
  4. Mar 18, 2009 #3


    User Avatar
    Gold Member

    Thanks Compuchip, btw,
    here's my code, if you can spot some errors, it will be a good deed:
    Code (Text):

    k = 1.38*10^-23
    m = 9.11*10^-31
    h = 6.63*10^-34
    N = 5*10^14
    FindRoot[(1/(N))*((2 \[Pi]mkT/h^2))^1.5*exp ((-1.6*10^5)/T) - 1, {T,
    Last edited: Mar 18, 2009
  5. Mar 19, 2009 #4


    User Avatar
    Science Advisor
    Homework Helper

    If you have separate variables, use spaces: Mathematica treats "\[Pi]mkT" as one variable, whereas you mean "\[Pi] m k T".
    Also, use Exp[ ... ] instead of exp( ... ) (with a capital and square brackets).
    Finally note that N is actually an existing function name (for example, N[\[Pi], 20]), you might want to use \[CapitalNu] (Escape-N-Escape) or a lower-case n or something like that.

    Aside: if you end the first four lines with a semicolon, it will not print the values:
    k = 3
    will output "3" when executed,
    k = 3;
    will also set k to 3 put not print the number.
  6. Mar 19, 2009 #5


    User Avatar
    Gold Member

    I must say that findroot is much better than Nsolve for this question.
  7. Jul 27, 2011 #6

    I've been trying to solve the system of equations given below for a while now:




    The equations work fine when I plug two of them in and set one variable to a constant, but when I try to solve all three Mathematica interprets the input incorrectly. My input is the following:

    findroot[{101.74=a+((0.055/(479248/c))*(352343+((479248/c)*a)-(158194*b/c)), 47205+((158194/c)*a)-((61842/c)*b)=68043.98+(299.73*b), 460584+(479248*(a^2)/(c^2))-(158194*b*a/(c^2))+(61842*(b^2)/(c^2))=21986+(3576*c)}, {a,90}, {b,140}, {c,90}]

    Which Mathematica interprets as 101.74==a. Any ideas or tips would be greatly appreciated.

  8. Jul 28, 2011 #7
    When I remove an extra ( and change = to == and correctly capitalize FindRoot I get

    In[2]:= FindRoot[{101.74==a+(0.055/(479248/c))*(352343+((479248/c)*a)-(158194*b/c)), 47205+((158194/c)*a)-((61842/c)*b)==68043.98+(299.73*b), 460584+(479248*(a^2)/(c^2))-(158194*b*a/(c^2))+(61842*(b^2)/(c^2))== 21986+(3576*c)},{a,90},{b,140},{c,90}]

    Out[2]= {a->92.1341,b->103.075,c->158.517}
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook