Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #14049
| From | "Kevin J. McCann" <kjm@KevinMcCann.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Problem with function definition inside DynamicModule |
| Date | 2013-04-04 17:10 +0000 |
| Message-ID | <kjkc64$7n6$1@smc.vnet.net> (permalink) |
| Organization | Time-Warner Telecom |
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
appreciated.
Thanks,
Kevin
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];
Panel[
Column[
{
Row[{"n", Spacer[5], SetterBar[Dynamic[n], Range[5]]}],
Dynamic@
Plot[f[x], {x, 0, 5}, Epilog -> p1[[1]],
PlotLabel -> "n = " <> ToString[n],
PlotRange -> {0, 30}]
}
](*Column*)
](*Panel*)
]
datafit[data]
Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread
Problem with function definition inside DynamicModule "Kevin J. McCann" <kjm@KevinMcCann.com> - 2013-04-04 17:10 +0000 Re: Problem with function definition inside DynamicModule debguy <johnandsara2@cox.net> - 2013-04-05 02:29 +0000 Re: Problem with function definition inside DynamicModule debguy <johnandsara2@cox.net> - 2013-04-05 02:29 +0000
csiph-web