Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. f[x_, y_] = E^((1/16) (x^2 + 4 y^2))
  2. m[x_, y_] = D[f[x, y], x];
  3. n[x_, y_] = D[f[x, y], y];
  4. {a, b} = {-.5, -.5};
  5. starterpoint = {a, b};
  6. Clear[x, y, t];
  7. equationx = x'[t] == m[x[t], y[t]];
  8. equationy = y'[t] == n[x[t], y[t]];
  9. starterx = x[0] == a;
  10. startery = y[0] == b;
  11. endtime = 2;
  12. approxsolutions = NDSolve[{equationx, equationy, starterx, startery}, {x[t], y[t]}, {t, 0, endtime}];
  13. Clear[trajectory];
  14. trajectory[t_] = {x[t] /. approxsolutions[[1]], y[t] /. approxsolutions[[1]]};
  15. trajectoryplot = ParametricPlot[trajectory[t], {t, 0, endtime}, PlotStyle -> {{Red, Thickness[0.015]}}];
  16. starterplot = Graphics[{Red, PointSize[0.06], Point[starterpoint]}];
  17. Show[gradfieldplot, starterplot, trajectoryplot, PlotRange -> All, Axes -> True, AxesLabel -> {"x", "y"}]
  18.  
  19.  
  20. {x[t_], y[t_]} = {a, b} + t gradf @@ {a, b}
  21. surfaceplot = Plot3D[f[x, y], {x, -1, 1}, {y, -1, 1}];
  22. traj = ParametricPlot3D[{x[t], y[t], f[x[t], y[t]]}, {t, 0, 2}, PlotStyle -> {Red, Thickness[0.01]}];
  23. Show[traj, surfaceplot, PlotRange -> Automatic]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement