Results 1 to 3 of 3

Math Help - the problem in mathematica

  1. #1
    xdu
    xdu is offline
    Newbie
    Joined
    Nov 2009
    Posts
    19

    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,
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Super Member
    Joined
    Aug 2008
    Posts
    903
    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}]
    Follow Math Help Forum on Facebook and Google+

  3. #3
    xdu
    xdu is offline
    Newbie
    Joined
    Nov 2009
    Posts
    19
    Shawsend,
    Thank you so much! the problem has been solved.
    thanks again!
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Mathematica problem
    Posted in the Math Software Forum
    Replies: 0
    Last Post: October 14th 2010, 05:33 AM
  2. Mathematica Problem
    Posted in the Math Software Forum
    Replies: 8
    Last Post: March 16th 2010, 11:00 AM
  3. Mathematica problem
    Posted in the Math Software Forum
    Replies: 2
    Last Post: December 16th 2009, 08:19 AM
  4. Mathematica Syntax problem?
    Posted in the Math Software Forum
    Replies: 0
    Last Post: October 11th 2009, 05:37 AM
  5. Mod and If Problem [Mathematica]
    Posted in the Math Software Forum
    Replies: 1
    Last Post: October 1st 2008, 10:02 AM

Search Tags


/mathhelpforum @mathhelpforum