Message Boards Message Boards

0
|
2115 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to use function from fitting without manually rewriting it?

Posted 10 years ago

Hi, I have some data, to which I am fitting a polynomial of degree 4.

In[112]:= funkcija = Fit[tocke, {1, x, x^2, x^3, x^4}, x]

Out[112]= 7655.48 - 1.37747*10^-16 x - 0.0000580449 x^2 + 
 1.0626*10^-23 x^3 - 8.35914*10^-13 x^4

Now what I need is actually derivative of this polynomial and I don't want to manually rewrite each coefficient, or is that really necessary?

In the end I am interested into values of the derivative in points from my first column of the imported data.

POSTED BY: Mitja Jan?i?
2 Replies

Well now I fell stupid. :D

Thanks for a nice and quick answer!

POSTED BY: Mitja Jan?i?

Dear Mitja,

sure, that's quite straight forward. Unfortunately, you did not provide the actual time series so I generated one that might be similar:

tocke = Table[{x, 7655.48 - 1.37747*10^-16 x - 0.0000580449 x^2 + 1.0626*10^-23 x^3 - 8.35914*10^-13 x^4 + 
     1000 RandomVariate[NormalDistribution[]]}, {x, 0, 10000, 100}];

You already fitted a function to that:

funkcija = Fit[tocke, {1, x, x^2, x^3, x^4}, x]

If you want a derivative you can try:

derfunkcija = D[Fit[tocke, {1, x, x^2, x^3, x^4}, x], x]

If you want you can evaluate that at all the points of the original time series.

Table[D[Fit[tocke, {1, x, x^2, x^3, x^4}, x], x] /. x -> xs, {xs, 0, 10000, 100}]

If you prefer taking the x-coordinates directly from the data file you can try this:

D[Fit[tocke, {1, x, x^2, x^3, x^4}, x], x] /. x -> # & /@ tocke[[All, 1]]

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

Group Abstract Group Abstract