MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Solving for coefficients...


  • To: mathgroup@smc.vnet.net
  • Subject: [mg12179] Re: Solving for coefficients...
  • From: Paul Abbott <paul@physics.uwa.edu.au>
  • Date: Fri, 1 May 1998 03:08:31 -0400
  • Organization: University of Western Australia
  • References: <6i0rvj$8jm@smc.vnet.net>

Rob Smith wrote:

> I am having difficulty getting Solve[] to deal with the following
> problem:
> 
>  m = c1 A + c2 B + c3 C ...
> 
> Where A, B, C etc. are known real numbers accurate to 4 decimal places
> and c1, c2, c3 etc. are positive integers (0 included).  I can measure
> m to within 10 parts per million error, I would then like to solve for
> the coefficients.
> 
> The two problems I see immediatly are 1) the coefficients can only be a
> positive integer or 0.  To deal with this I have tried including in the
> body of Solve[] c1 >= 0 and IntegerQ[c1] == True.  The other problem is
> that there is error in my measurement, I have tried to deal with this
> by putting the above equation into solve as two equations m >= 100.01,
> m <= 100.00, for example.
> 
> Obviously this strategy has not worked.  Any suggestions as to how to
> approach this problem using Mathematica would be greatly appreciated.
> 
> Should any one care about the application, these are mass spectrometry
> data for which I am trying to solve for consistent chemical formulae.

Here is one approach which uses LatticeReduce (see the Mathematica
Journal 6(2): 29-30).  Define NValues for a, b, c etc., e.g.,

In[3]:= N[a,___]:=1.2303; N[b,_]:=4.5326; N[c,_]=5.2113;

Note that you can define a numerical value for a symbol _without_ using
a=1.2303, etc.  The second argument (___) means that Numerical
evaluation to any precision still yields the same answer.  

Now we can use TranscendentalRecognize (whose code is given below and is
taken from the Mathematica Journal without change) to determine the c1,
c2, c3 for m having the value 59.2406``5 (the 5 effectively indicates
the 10 parts per million error):

In[3]:= TranscendentalRecognize[59.2406``5,{a,b,c}] Out[3]= 8 a+4 b+6 c

The result is returned as integer multipliers of a, b, c.  Numerically
evaluating the result,

In[4]:= N[%]
Out[4]= 59.2406

we get good agreement.  TranscendentalRecognize is _not_ optimal for
your application but I think the essential idea is correct.  Lattice
reduction should be able to do what you want.

Another thought: perhaps ProjectiveRationalize in
NumberTheory`Rationalize` can be used for this?

Cheers,
	Paul 
___________________________________________________________________________________

TranscendentalRecognize[n_, basis_] := 
  Module[{c, d, digs, e, id, lat, powerten, r, s, vals}, 
   {d, e} = RealDigits[n]; s = Sign[n]; c = FromDigits[d]; 
	powerten = 10^(Length[d] - e); 
    digs = (RealDigits[N[#1, -e + Length[d] + 5]] & ) /@ basis; 
    r = (FromDigits[Take[First[#1], -e + Last[#1] + Length[d]]] & ) /@
digs; 
    lat = Transpose[Append[IdentityMatrix[Length[basis] + 2], 
		Flatten[{powerten, r, c}]]]; 
    vals = Take[First[LatticeReduce[lat]], Length[basis] + 2]; 
    Expand[-((s*(Take[vals, {2, -2}] . basis +
First[vals]))/Last[vals])]]


____________________________________________________________________ 
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia            Nedlands WA  6907       
mailto:paul@physics.uwa.edu.au  AUSTRALIA                            
http://www.pd.uwa.edu.au/~paul

            God IS a weakly left-handed dice player
____________________________________________________________________



  • Prev by Date: RE: How find the max value of the one 3D function in a interval?
  • Next by Date: Re: Q. about Solve as applied to vector equations
  • Prev by thread: RE: How find the max value of the one 3D function in a interval?
  • Next by thread: Re: Solving for coefficients...