Advertisement
UF6

Untitled

UF6
Jan 30th, 2020
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. gradientFieldPlot[f_, rx_, ry_, opts : OptionsPattern[]] :=
  2. Module[{img, cont, densityOptions, contourOptions, frameOptions,
  3. gradField, field, plotRangeRule, rangeCoords},
  4. densityOptions =
  5. Join[FilterRules[{opts},
  6. FilterRules[Options[DensityPlot],
  7. Except[{Prolog, Epilog, FrameTicks, PlotLabel, ImagePadding,
  8. GridLines, Mesh, AspectRatio, PlotRangePadding, Frame,
  9. Axes}]]], {PlotRangePadding -> None, Frame -> None,
  10. Axes -> None, AspectRatio -> Automatic}];
  11. contourOptions =
  12. Join[FilterRules[{opts},
  13. FilterRules[Options[ContourPlot],
  14. Except[{Prolog, Epilog, FrameTicks, PlotLabel, Background,
  15. ContourShading, PlotRangePadding, Frame, Axes,
  16. ExclusionsStyle}]]], {PlotRangePadding -> None, Frame -> None,
  17. Axes -> None, ContourShading -> False}];
  18. gradField = ComplexExpand[{D[f, rx[[1]]], D[f, ry[[1]]]}];
  19. field =
  20. DensityPlot[Norm[gradField], rx, ry,
  21. Evaluate@Apply[Sequence, densityOptions]];
  22. img = Rasterize[field, "Image"];
  23. plotRangeRule = FilterRules[Quiet@AbsoluteOptions[field], PlotRange];
  24. cont = If[
  25. MemberQ[{0,
  26. None}, (Contours /. FilterRules[{opts}, Contours])], {},
  27. ContourPlot[f, rx, ry, Evaluate@Apply[Sequence, contourOptions]]];
  28. frameOptions =
  29. Join[FilterRules[{opts},
  30. FilterRules[Options[Graphics],
  31. Except[{PlotRangeClipping, PlotRange}]]], {plotRangeRule,
  32. Frame -> True, PlotRangeClipping -> True}];
  33. rangeCoords = Transpose[PlotRange /. plotRangeRule];
  34. Apply[Show[
  35. Graphics[{Inset[
  36. Show[SetAlphaChannel[img,
  37. "ShadingOpacity" /. {opts} /. {"ShadingOpacity" -> 1}],
  38. AspectRatio -> Full], rangeCoords[[1]], {0, 0},
  39. rangeCoords[[2]] - rangeCoords[[1]]]}], cont,
  40. StreamPlot[gradField, rx, ry,
  41. Evaluate@FilterRules[{opts}, StreamStyle],
  42. Evaluate@FilterRules[{opts}, StreamColorFunction],
  43. Evaluate@FilterRules[{opts}, StreamColorFunctionScaling],
  44. Evaluate@FilterRules[{opts}, StreamPoints],
  45. Evaluate@FilterRules[{opts}, StreamScale]], ##] &, frameOptions]]
  46.  
  47.  
  48. gradientFieldPlot[(lam/(4*3.14*
  49. ep)) - (ln (((x + 1)^2 + y^2)/((x - 1)^2 + y^2))), {x, -15.5,
  50. 15.5}, {y, -20.5, 20.5}, {lam, -3, 3}, {ep, -10, 10},
  51. PlotPoints -> 50, ColorFunction -> "BlueGreenYellow", Contours -> 10,
  52. ContourStyle -> White, Frame -> True, FrameLabel -> {"x", "y"},
  53. ClippingStyle -> Automatic, Axes -> True, StreamStyle -> Green]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement