To solve an equation numerically using mathematica.

  • Mathematica
  • Thread starter MathematicalPhysicist
  • Start date
  • Tags
    Mathematica
In summary, the third equation in the system is not solved correctly by Mathematica. It appears to be trying to solve for c instead of b, and then multiplying by a.
  • #1
MathematicalPhysicist
Gold Member
4,699
371
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.
:uhh:
 
Physics news on Phys.org
  • #2
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).
 
  • #3
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:
  • #4
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.
 
  • #5
I must say that findroot is much better than Nsolve for this question.
Thanks.
 
  • #6
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
 
  • #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}
 

1. How do I solve an equation numerically using Mathematica?

To solve an equation numerically using Mathematica, you can use the built-in function NSolve. This function will find numerical solutions to your equation by using numerical methods and approximation techniques.

2. What is the syntax for using NSolve in Mathematica?

The syntax for NSolve is NSolve[equation, variables], where equation is the equation you want to solve and variables is a list of the variables in the equation. You can also add additional options to customize the output.

3. Can I solve a system of equations numerically using Mathematica?

Yes, you can use NSolve to solve a system of equations numerically. Simply input the equations as a list and provide a list of the variables in the system. You can also add additional options to specify the domain and precision of the solutions.

4. How do I plot the solutions to my equation in Mathematica?

You can use the Plot function in Mathematica to plot the solutions to your equation. Simply input the equation and the range of values for the variable you want to plot. You can also customize the appearance of the plot by adding options such as PlotStyle and AxesLabel.

5. Is it possible to find complex solutions to an equation using Mathematica?

Yes, NSolve can also find complex solutions to equations. By default, it will only give real solutions, but you can specify Complexes as the domain to find all complex solutions. You can also use the Re and Im functions to separate the real and imaginary parts of the solutions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
358
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
201
  • Precalculus Mathematics Homework Help
Replies
6
Views
532
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
Back
Top