Last active
December 16, 2015 01:09
-
-
Save pwl/5353171 to your computer and use it in GitHub Desktop.
Zbieżność pochodnej z funkcji analitycznej i nieanalitycznej w przedostatnim punkcie siatki. Punkty oznaczają błąd bezwzględny (niebieski) i względny (fioletowy).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$MaxExtraPrecision = 1000; | |
der[f_, k_, rk_, h_] := | |
NDSolve`FiniteDifferenceDerivative[Derivative[k], h Range[0, 100], | |
f /@ (h Range[0, 100]), DifferenceOrder -> rk]; | |
abserr[f_, k_, rk_] := | |
Abs[der[f, k, rk, #][[2]] - | |
Derivative[k][f][#]] & /@ (2^-Range[1, 30]); | |
relerr[f_, k_, rk_] := | |
abserr[f, k, rk]/Abs@(Derivative[k][f] /@ (2^-Range[1, 30])); | |
graph[{f1_, f2_}, k_, rk_] := | |
GraphicsRow[ | |
ListPlot[N[Log[10, {abserr[#, k, rk], relerr[#, k, rk]}], 1000], | |
PlotLabel -> #["y"], AxesLabel -> {"n", "Error"}] & /@ {f1, f2}, | |
PlotLabel -> | |
StringForm[ | |
"Pochodna \!\(\*FractionBox[SuperscriptBox[\(d\), \(`1`\)], \ | |
SuperscriptBox[\(dy\), \(`1`\)]]\) w punkcie \ | |
\!\(\*SubscriptBox[\(y\), \(1\)]\)=\!\(\*SuperscriptBox[\(2\), \ | |
\(-n\)]\) (dla \!\(\*SubscriptBox[\(y\), \(k\)]\)=kh, \ | |
h=\!\(\*SuperscriptBox[\(2\), \(-n\)]\)), błąd metody to \ | |
O(\!\(\*SuperscriptBox[\(h\), \(`2`\)]\))", k, rk], | |
ImageSize -> Large] | |
f = {Sin, Function[y, If[y == 0, 0, y^2 Log[y]]]}; | |
graph[f, 1, 6] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment