New in Wolfram
Mathematica
8: Dynamic Library Loading
◄
previous
|
next
►
Software Development
Integration with NDSolve
Mathematica
functions can take C code as input. This shows
NDSolve
computing Duffing's equation using the Runge-Kutta method.
In[1]:=
X
advancelf = LibraryFunctionLoad["demo_numerical", "duffing_crk4", {{Real, _}, Real, Real}, {Real, _}]; refinelf = LibraryFunctionLoad["demo_numerical", "refine", {Real, {Real, 2}}, {Real, 2}]; v = {{0., 0.01}, {0., 0.}}; dist = 0.025; \[CapitalDelta]t = 0.1; \[CapitalDelta]T = 1.0; Tend = 60; plots = Table[ Do[v = advancelf[refinelf[dist, v], t - \[CapitalDelta]t, t], {t, T - 1 + \[CapitalDelta]t, T, \[CapitalDelta]t}]; points = Transpose[v]; Graphics[ Line[points, VertexColors -> Map[Hue, N[Range[Length[points]]]/Length[points]]], Axes -> True, PlotRange -> {{-1.5, 1.5}, {-1, 1}}], {T, \[CapitalDelta]T, Tend, \[CapitalDelta]T }];
In[2]:=
X
Take[plots, {10, 60, 10}]
Out[2]=