When I solve this equation in Mathematica 8, I can get the right answer, but with some uncomfortable warnings.
Equation:
Solve[-26.81 == 194 k + k*l*32.9 && 22.2 == -74 k + k*l* 59.7, {k, l}]
Warnings:
Solve::ratnz: Solve was unable to solve the system with inexact coefficients. The answer was obtained by solving a corresponding exact system and numericizing the result. >>
If I transform the above equation to the following, then it works fine, but this is not convenient:
{k, kl/k} /. Solve[-26.81 == 194 k + kl*32.9 && 22.2 == -74 k + kl* 59.7, {k, kl}]
So my question is, how can I get rid of such warnings?
Answer
You can get rid of the warning by converting everything to exact numbers yourself before passing the equation to Solve
(the warning message suggests that this is what Solve
does itself):
In[2]:= Rationalize[-26.81 == 194 k + k*l*32.9 && 22.2 == -74 k + k*l*59.7]
Out[2]= -(2681/100) == 194 k + (329 k l)/10 && 111/5 == -74 k + (597 k l)/10
In[3]:= Solve[%]
Out[3]= {{l -> -(2322860/2330937), k -> -(2330937/14016400)}}
In[4]:= N[%]
Out[4]= {{l -> -0.996535, k -> -0.166301}}
Solve
(like all symbolic manipulation function) is meant to be used with exact numbers where roundoff errors are not an issue. For solving the equation numerically, use NSolve
:
In[5]:= NSolve[-26.81 == 194 k + k*l*32.9 && 22.2 == -74 k + k*l*59.7]
Out[5]= {{l -> -0.996535, k -> -0.166301}}
Some background on exact and inexact numbers:
In Mathematica, any number with a decimal point in it is considered to be inexact, i.e. known only to a certain number of digits.
2
is exact,2.0
is inexact machine precision and2.0`5
is inexact arbitrary precision known to 5 digits.Symbolic computations (
Integrate
,Solve
,Reduce
, etc.) work best with exact numbers. Try to avoid inexact numbers with such functions.See more on Numbers
Comments
Post a Comment