Group Abstract Group Abstract

Message Boards Message Boards

Universal data (graph) fitting

Posted 11 years ago
Attachments:
POSTED BY: Sungwoo Yang
3 Replies
Posted 11 years ago

Hi Marco,

Thank you so much. This is exactly what I was looking for. You are awesome.

POSTED BY: Sungwoo Yang

Hi,

I forgot to say that this works of course also if you want to add legends.

M = 10; data = RandomReal[1, M];
Manipulate[
 Show[ListPlot[data, PlotStyle -> Red], 
  Plot[Evaluate[
    Normal[NonlinearModelFit[data, 
      Evaluate[Sum[Subscript[a, i] x^i, {i, 0, d}]], 
      Evaluate[Table[Subscript[a, i], {i, 0, d}]], x]]], {x, 0, 
    M + 1}, PlotRange -> All , 
   PlotLegends -> 
    Placed["Polynomial \nf(x)=" <> 
      ToString[
       TraditionalForm[
        Evaluate[
         Normal[NonlinearModelFit[data, 
           Evaluate[Sum[Subscript[a, i] x^i, {i, 0, d}]], 
           Evaluate[Table[Subscript[a, i], {i, 0, d}]], x]]]]], 
     Below]]], {d, 0, 10}]

Cheers,

M.

POSTED BY: Marco Thiel

Hi,

this function might be useful:

nlm[d_, data_] := NonlinearModelFit[data, Evaluate[Sum[Subscript[a, i] x^i, {i, 0, d}]], Evaluate[Table[Subscript[a, i], {i, 0, d}]], x] 

d is the dimension of the polynomial and data is the list of points.

Here's an interactive interface:

M = 10; data = RandomReal[1, M];Manipulate[
Show[ListPlot[data, PlotStyle -> Red], Plot[Evaluate[Normal[NonlinearModelFit[data, Evaluate[Sum[Subscript[a, i] x^i, {i, 0, d}]], 
Evaluate[Table[Subscript[a, i], {i, 0, d}]], x]]], {x, 0, M + 1}, PlotRange -> All ]], {d, 0, 10}]

Some of the Evaluate functions are redundant. The thing looks like this:

enter image description here

Cheers,

Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard