       Modifying Fit[] using SingularValues

• To: mathgroup at smc.vnet.net
• Subject: [mg23418] Modifying Fit[] using SingularValues
• From: "William F. Campbell" <valentin at wam.umd.edu>
• Date: Sun, 7 May 2000 21:18:03 -0400 (EDT)
• Organization: UMD Dept. of Meteorology
• Sender: owner-wri-mathgroup at wolfram.com

I am writing my own function based on Fit[] so that it can show
variance for each parameter and chi-squared, as well as tell you when
two fitting functions are linearly dependent (or nearly so) for a
given set of data.
So far I have the following:

Given a list of functions, basis={f1,f2,f3}, and a set of dependent
coordinates, testx={1.,3.,5.,8.,11.}, I can produce the design matrix
using a slight modification to a "trick" due to Bob Hanlon,

designMatrix:=Outer[#2[#1]&,testx,basis]

So if for example f1[x_]:=1, f2[x_]:=x, and f3[x_]:=x^2, I get

designMatrix//MatrixForm

1.  1.  1.
1.  3.  9.
1.  5.  25.
1.  8.  64.
1.  11. 121.

Then I can use SingularValues[designMatrix] to obtain U, w, and V, in
terms of which the best fit parameters for a set of data testy can be
computed as follows:

a=((U.testy)/w).V

('a' is the vector of coefficients for each of the functions in basis)
It's easy with this approach to detect linear dependence and eliminate
it, and also compute chisquared and the variance for individual
parameters.

What I want to do and can't figure out, is how to take a list of
expressions like {1,x,x^2} and use them like I used the explicitly
defined functions f1, f2, and f3 above.  So then I could define a
function myFit which would be invoked like Fit, i.e.

myFit[Transpose[{testx,testy}],{1,x,x^2,Sin[x]},x]

and yield a1 + a2 x + a3 x^2 + a4 Sin[x], along with chisquared and
the variance for each parameter.

Bill Campbell

• Prev by Date: extracting column data from 2D Matrix
• Next by Date: Re: [Q] Solve?
• Previous by thread: Re: extracting column data from 2D Matrix
• Next by thread: Re: Modifying Fit[] using SingularValues