To solve an equation numerically using mathematica.

  • Context: Mathematica 
  • Thread starter Thread starter MathematicalPhysicist
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary

Discussion Overview

The discussion focuses on solving equations numerically using Mathematica, specifically addressing the Saha equation and a system of equations involving multiple variables. Participants seek advice on command lines and methods suitable for numerical solutions.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant inquires about commands in Mathematica to solve the Saha equation numerically for temperature (T) when the ratio is 1.
  • Another participant suggests using NSolve for simpler equations and FindRoot for more complex numerical solutions, providing examples of both methods.
  • A participant shares their code for solving the Saha equation and requests feedback on potential errors.
  • Another participant points out specific syntax issues in the provided code, such as the need for spaces between variables and the correct capitalization of functions.
  • One participant expresses a preference for FindRoot over NSolve for the given problem.
  • A new participant presents a system of equations they are trying to solve and describes issues with Mathematica interpreting their input incorrectly.
  • A later reply corrects the syntax of the system of equations, suggesting the use of '==' instead of '=' and addressing other formatting issues.

Areas of Agreement / Disagreement

Participants generally agree on the utility of FindRoot for numerical solutions, but there are differing opinions on the best approach for specific equations and syntax issues remain unresolved.

Contextual Notes

Participants highlight limitations related to syntax and function names in Mathematica, as well as the need for proper formatting when inputting equations.

MathematicalPhysicist
Science Advisor
Gold Member
Messages
4,662
Reaction score
372
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.

Cheers.
:rolleyes:
 
Physics news on Phys.org
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).
 
Thanks Compuchip, btw,
here's my code, if you can spot some errors, it will be a good deed:
Code:
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, 
  10000}]
 
Last edited:
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.
 
I must say that findroot is much better than Nsolve for this question.
Thanks.
 
Hi,

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

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)

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.

Thanks
 
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}
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K