How do I plot a slope field using mathematica? -
How do I plot a slope field using mathematica? -
i trying plot slope fields of differential equations using mathematica can't figure out. have equation
y' = y(t) y(t) = c * e^t
how plot slope field?
i found illustration way complex me understand http://demonstrations.wolfram.com/slopefields/
the command need (since version 7) vectorplot
. there examples in documentation.
i think case you're interested in differential equation
y'[x] == f[x, y[x]]
in case gave in question,
f[x_, y_] := y
which integrates exponential
in[]:= sol = dsolve[y'[x] == f[x, y[x]], y, x] out[]= {{y -> function[{x}, e^x c]}}
we can plot slope field (see wikibooks:ode:graphing) using
vectorplot[{1, f[x, y]}, {x, -2, 2}, {y, -2, 2}]
this can plotted solutions de using like
show[vectorplot[{1, f[x, y]}, {x, -2, 2}, {y, -2, 8}, vectorstyle -> arrowheads[0.03]], plot[evaluate[table[y[x] /. sol, {c, -10, 10, 1}]], {x, -2, 2}, plotrange -> all]]
maybe more interesting illustration gaussian
in[]:= f[x_, y_] := -x y in[]:= sol = dsolve[y'[x] == f[x, y[x]], y, x] /. c[1] -> c out[]= {{y -> function[{x}, e^(-(x^2/2)) c]}} show[vectorplot[{1, f[x, y]}, {x, -2, 2}, {y, -2, 8}, vectorstyle -> arrowheads[0.026]], plot[evaluate[table[y[x] /. sol, {c, -10, 10, 1}]], {x, -2, 2}, plotrange -> all]]
finally, there related concept of gradient field, @ gradient (vector derivative) of function:
in[]:= f[x_, y_] := sin[x y] d[f[x, y], {{x, y}}] vectorplot[%, {x, -2, 2}, {y, -2, 2}] out[]= {y cos[x y], x cos[x y]}
wolfram-mathematica plot differential-equations
Comments
Post a Comment