# Thread: the problem in mathematica

1. ## 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?

kind regards,

2. 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}]

3. Shawsend,
Thank you so much! the problem has been solved.
thanks again!