| 
November 6th, 2009, 06:55 AM
| | Newbie | | Join Date: Nov 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
| | the problem in mathematica Hi all, I have a problem about findfit command.
There are three data sets I have as follows:
x={35.16, 35.33, 35.33, 35.33, 35.33, 35.34, 36.07, 36.07, 36.07, 36.09, 36.51, 36.51, 36.52, 36.52, 36.52, 36.52, 36.75, 36.77, 36.77,36.92, 36.84, 36.86, 36.86, 36.91, 36.92, 36.92, 36.92, 37.05, 37.11,37.86}
y={7., 5., 30., 5., 20., 10., 25., 5., 8., 20., 20., 10., 10., 30., 30., 5., 13., 30., 25., 9., 8., 10., 30., 27., 10., 15., 5., 35., 8.,45.}
z={10.91, 18.07, 17.39, 14.33, 15.25, 15.44, 7.02, 11.72, 11.50, 7.67,7.14, 10.29, 7.24, 8.46, 8.96, 12.65, 5.24, 4.60, 6.26, 6.12, 5.66, 6.31, 3.45, 10.10, 7.30, 5.30, 10.78, 2.89, 4.39, 4.25}
and then I transposed the data:
m={x,y,z}
I want to use the model z=(a*x + d)/( b*Sign[c - x]*y)to fit these data by the following command:
FindFit[m,(a*x + d)/( b*Sign[c - x]*y),{a, b, c, d}, {x, y}]
but I got the error as
General::ivar: {35.16,35.33,35.33,35.33,35.33,35.34,36.07,36.07,3 6.07,36.09,36.51,36.51,36.52,36.52,36.52,36.52,36. 75,36.77,36.77,36.92,36.84,36.86,36.86,36.91,36.92 ,36.92,36.92,37.05,37.11,37.86} is not a valid variable. >>
I don't know how to solve this problem.
Anybody knows what's wrong here?
Many thanks in advance!
kind regards, | 
November 6th, 2009, 11:37 AM
| | Super Member | | Join Date: Aug 2008
Posts: 601
Country: Thanks: 46
Thanked 261 Times in 226 Posts
| | You need to put the data into the form {{x1,y1,z1},{x2,y2,z20}...}. Also, the x,y,z you're using for the tables is conflicting with the variable names x,y,z you use in FindFit so I changed them. Note I use MapThread to put the data into the correct form, used ListPlot3D to see what the actual data looks like, then (a*x + d)/(b*Sign[c - x]*y) /. myCoeff to plot the resulting fit. Mathematica still reports a problem with the data but does calculate the coefficients.
Clear[x, y, z];
xtab = {35.16, 35.33, 35.33, 35.33, 35.33, 35.34, 36.07, 36.07, 36.07,
36.09, 36.51, 36.51, 36.52, 36.52, 36.52, 36.52, 36.75, 36.77,
36.77, 36.92, 36.84, 36.86, 36.86, 36.91, 36.92, 36.92, 36.92,
37.05, 37.11, 37.86}
ytab = {7., 5., 30., 5., 20., 10., 25., 5., 8., 20., 20., 10., 10.,
30., 30., 5., 13., 30., 25., 9., 8., 10., 30., 27., 10., 15., 5.,
35., 8., 45.}
ztab = {10.91, 18.07, 17.39, 14.33, 15.25, 15.44, 7.02, 11.72, 11.50,
7.67, 7.14, 10.29, 7.24, 8.46, 8.96, 12.65, 5.24, 4.60, 6.26, 6.12,
5.66, 6.31, 3.45, 10.10, 7.30, 5.30, 10.78, 2.89, 4.39, 4.25}
myData = MapThread[{#1, #2, #3} &, {xtab, ytab, ztab}]
ListPlot3D[myData]
myCoeff =
FindFit[myData, (a*x + d)/(b*Sign[c - x]*y), {a, b, c, d}, {x, y}]
Plot3D[(a*x + d)/(b*Sign[c - x]*y) /. myCoeff, {x, 35, 37}, {y, 5,
30}]
__________________ "I am beset by the ironies in my life" | 
November 6th, 2009, 02:25 PM
| | Newbie | | Join Date: Nov 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
| | Shawsend,
Thank you so much! the problem has been solved.
thanks again! | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | All times are GMT -7. The time now is 07:18 AM. | | |