Math Help Forum

Math Help Forum Feed Site Feed

Go Back   Math Help Forum > Math Resources > Mathematics Software Discussion
Reply
 
Thread Tools Display Modes
  #1  
Old November 6th, 2009, 06:55 AM
xdu xdu is offline
Newbie
 
Join Date: Nov 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
xdu is on a distinguished road
Default 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,
Reply With Quote
Advertisement
 
  #2  
Old November 6th, 2009, 11:37 AM
Super Member
 
Join Date: Aug 2008
Posts: 601
Country:
Thanks: 46
Thanked 261 Times in 226 Posts
shawsend is a jewel in the roughshawsend is a jewel in the roughshawsend is a jewel in the roughshawsend is a jewel in the rough
Default

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"
Reply With Quote
  #3  
Old November 6th, 2009, 02:25 PM
xdu xdu is offline
Newbie
 
Join Date: Nov 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
xdu is on a distinguished road
Default

Shawsend,
Thank you so much! the problem has been solved.
thanks again!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -7. The time now is 07:18 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
©2005 - 2009 Math Help Forum


Math Help Forum is a community of maths forums with an emphasis on maths help in all levels of mathematics.
Register to post your math questions or just hang out and try some of our math games or visit the arcade.