The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Problem with function definition inside DynamicModule
Replies: 1   Last Post: Apr 6, 2013 5:10 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Kevin J. McCann

Posts: 147
Registered: 12/7/04
Problem with function definition inside DynamicModule
Posted: Apr 4, 2013 1:10 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I am trying to write a dynamic module that does a polynomial fit with
different orders of the polynomial. I define f[x], the fit within the
module, but it does not update. If I try a delayed equals in the
definition, I get lots of unpleasant error messages. Any help would be



data = Table[{x, x^2 + RandomReal[{-1, 1}]}, {x, 0, 5}];

datafit[dat_?ListQ] :=
DynamicModule[{m, d, f, x, y, k, n = 1, p1, powers},
p1 = ListPlot[dat, Joined -> False,
PlotStyle -> {Red, AbsolutePointSize[7]}, PlotRange -> All];

(* Here is where I think the problem is *)
f[x_] = Fit[dat, Table[x^k, {k, 0, n}], x];

Row[{"n", Spacer[5], SetterBar[Dynamic[n], Range[5]]}],
Plot[f[x], {x, 0, 5}, Epilog -> p1[[1]],
PlotLabel -> "n = " <> ToString[n],
PlotRange -> {0, 30}]


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.