Advertisement
Guest User

Untitled

a guest
Dec 17th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. Clear[a, b, x, y, t, endtime];
  2.  
  3. surfaceplot = Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, PlotRange -> All, BoxRatios -> Automatic, MaxRecursion -> 4, AxesLabel -> {"x", "y", "z"}];
  4.  
  5. {a, b} = {.5, -1};
  6. startingpoint3Dplot = Graphics3D[{Red, Sphere[{a, b, f[a, b]}, 0.2]}];
  7. gradf[x_, y_] = {D[f[x, y], x], D[f[x, y], y]};
  8. equationx = x'[t] == gradf[x[t], y[t]][[1]];
  9. equationy = y'[t] == gradf[x[t], y[t]][[2]];
  10. starterx = x[0] == a;
  11. startery = y[0] == b;
  12. endtime = 80;
  13. approxsolutions = NDSolve[{equationx, equationy, starterx, startery}, {x[t], y[t]}, {t, 0, endtime}];
  14. gradtrajectory[t_] = {x[t] /. approxsolutions[[1]], y[t] /. approxsolutions[[1]]};
  15. gradtrajectory3D[t_] = Join[gradtrajectory[t], {f @@ gradtrajectory[t]}];
  16. gradtrajectory3Dplot = ParametricPlot3D[gradtrajectory3D[t], {t, 0, endtime}, PlotStyle -> {Orange, Thickness[0.015]}];
  17. Show[surfaceplot, gradtrajectory3Dplot, startingpoint3Dplot, PlotRange -> All, AxesLabel -> {"x", "y", "z"}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement