Mathematica To solve an equation numerically using mathematica.

  • Thread starter Thread starter MathematicalPhysicist
  • Start date Start date
  • Tags Tags
    Mathematica
AI Thread Summary
The discussion focuses on solving equations numerically using Mathematica, specifically the Saha equation when the ratio is 1 to extract temperature (T). A user seeks command line solutions and is advised to use NSolve for simpler equations, while FindRoot is recommended for more complex scenarios, requiring an initial guess for the solution. The importance of proper syntax is emphasized, including the use of "==" for equations and capitalizing function names like Exp. Another user shares a complex system of equations and encounters issues with Mathematica interpreting the input correctly. They are guided to correct their syntax by replacing "=" with "==" and removing extra parentheses. After making these adjustments, they successfully obtain numerical solutions for the variables a, b, and c. The conversation highlights the need for attention to detail in coding within Mathematica to ensure accurate results.
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
Views
3K
Replies
4
Views
2K
Replies
4
Views
1K
Replies
5
Views
3K
Replies
1
Views
2K
Back
Top