Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Newbie Plot-Fit Questions.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg31120] RE: [mg31116] Newbie Plot-Fit Questions.
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 12 Oct 2001 03:36:37 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

SkyBeaux,

Attributes[Plot]
{HoldAll, Protected}

This means that your fit command is Held and is evaluate once for each value
of x in the plot. Worse yet, x in the Fit command is first replaced
everywhere by the value of x in the iterator and Fit then evaluated. So for
x = 6000 you obtain:

Fit[{{2942, 3650782}, {2955, 2255796}, {3204, 730421},
   {4105, 1740135}, {7815, 6329111}, {13097, 7116844}},
  {1, 6000, 6000^2, 6000^3}, 6000]
3.8087964865751304*^6

Not what you wanted. The solution is to evaluate Fit in the plot command.
This will work.

Plot[Evaluate[Fit[{{2942, 3650782}, {2955, 2255796},
     {3204, 730421}, {4105, 1740135}, {7815, 6329111},
     {13097, 7116844}}, {1, x, x^2, x^3}, x]],
  {x, 2942, 13097}]

But I would hesitate to write the command that way in the first place. I
would prefer something like the following where you can also see what the
fit was.

Fit[{{2942, 3650782}, {2955, 2255796}, {3204, 730421},
   {4105, 1740135}, {7815, 6329111}, {13097, 7116844}},
  {1, x, x^2, x^3}, x]
Plot[%, {x, 2942, 13097}];
1.7044496230729986*^7 - 8507.38287339198*x +
  1.3901134594316935*x^2 - 0.00006096360495406324*x^3
(plus the graph)

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/


> From: SkyBeaux [mailto:realbeaux at yahoo.com]
To: mathgroup at smc.vnet.net
>
> Please explain this to me:
>
> If I do the following:
>
> Fit[{{2942, 3650782}, {2955, 2255796}, {3204, 730421}, {4105,
> 1740135}, {7815,
>        6329111}, {13097, 7116844}}, {1, x, x^2, x^3}, x]
>
> Results are:
> \!\(1.7044496230729986`*^7 - 8507.38287339198`\ x +
>     1.3901134594316935`\ x\^2 - 0.00006096360495406324`\ x\^3\)
>
> Then I plot the results as follows:
>
> \!\(Plot[1.7044496230729986`*^7 - 8507.38287339198`\ x +
>       1.3901134594316935`\ x\^2 - 0.00006096360495406324`\ x\^3, {x,
> 2942,
>       13097}]\)
>
> I get a nice "sin" looking plot.  (This is what I want.)
>
> However if I try to combine the two statements into one.  Like this:
>
> Plot[(Fit[{{2942, 3650782}, {2955, 2255796}, {3204, 730421}, {4105,
>           1740135}, {7815, 6329111}, {13097, 7116844}}, {1, x, x^2,
> x^3},
>       x]), {x, 2942, 13097}]
>
> I get a linear chart.
>
> What is the difference?  And how do I get my nice "sin" looking plot
> back?
>
> As you can see, I an not really sure what is being plotted by the
> first set of commands, but I think it is a log plot.
>
> Thanks for you help.
>
> --SB
>



  • Prev by Date: patterns
  • Next by Date: Re: Using NDSolve for 2-variables function ?
  • Previous by thread: Re: Newbie Plot-Fit Questions.
  • Next by thread: another question.