3
$\begingroup$

First, I should say I am at best an advanced amateur at Mathematica, and that generally speaking my knowledge of programming (in any language) is more in computation than visualization.

There is a model I am working on for which I have recently shown there is a feasibility region: $$\mathcal{R} = \{(x,y) \in [0,\infty)\times[0, \infty) : x+y \leq L\}.$$ Of course this is a triangular subregion of the first quadrant. I wish to restrict the domain of the streamplots I am generating to $\mathcal{R}$.

From looking at the documentation I have constructed the following code:

StreamPlot[{dx/dt, dy/dt}, {x, 0, L}, {y, 0, L}]

which works fine, but of course gives me a large amount of unneeded data that clutters up my attempted visualization. So then, my question is:

How do I restrict the domain of StreamPlot to $\mathcal{R} $?

$\endgroup$
2
  • 1
    $\begingroup$ Welcome to Mathematica.se! Full minimalistic code to demonstrate the issue, please! Then it is much easier for us to help you out! $\endgroup$
    – Johu
    Sep 22, 2018 at 21:07
  • $\begingroup$ Closely related to DensityPlot with equal mesh and a certain boundary $\endgroup$
    – Johu
    Sep 22, 2018 at 21:14

2 Answers 2

1
$\begingroup$

Try

StreamPlot[{dx/dt, dy/dt}, {x, 0, L}, {y, 0, L}, RegionFunction -> Function[{x, y}, x+y <= L]]
$\endgroup$
0
4
$\begingroup$
StreamPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}, 
 RegionFunction -> Function[{x, y, z}, 2 < x^2 + y^2 < 9]]

enter image description here

or

StreamPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, y} \[Element] 
  StadiumShape[{{0, 0}, {2, 3}}, 2]]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you very much for your help. This code will be very helpful if I ever need to plot a circular region. $\endgroup$
    – GeauxMath
    Sep 22, 2018 at 21:19
  • $\begingroup$ Just to demonstrate that the solution is not limted to circlar region, I updated the answer with a more compelx shape. $\endgroup$
    – Johu
    Sep 22, 2018 at 21:28
  • $\begingroup$ it's like a fingerprint! $\endgroup$ Jul 16, 2020 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.