ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 08 Nov 2018 19:01:11 +0100Restriction of domain of vector fieldhttps://ask.sagemath.org/question/44207/restriction-of-domain-of-vector-field/I was trying to plot a field of normal vectors to a given implicit graph. What I got so far is:
x, y = var('x y')
f(x,y) = 2*x*y^3
g(x,y) = x^2*3*y^2
d = plot_vector_field((f(x,y)/sqrt(f(x,y)^2+g(x,y)^2),g(x,y)/sqrt(f(x,y)^2+g(x,y)^2)), (x,-5,5), (y,-5,5))
s = implicit_plot(x^2*y^3-1 , (x,-5,5), (y,-5,5))
show(s+d)
And it works like a charm, however, is there a way to "restrict" a domain of plot_vector_field so it doesn't plot all the vectors in a given range, but only for point (x,y) lying on my graph? That is such points that x^2*y^3=1. I tried to just put it instead (y,-5,5) (in a y=(1/x^2)^(1/3) form), but it obviously doesn't work.
Thx for any help as I'm new to Sage.Tue, 06 Nov 2018 21:04:40 +0100https://ask.sagemath.org/question/44207/restriction-of-domain-of-vector-field/Answer by eric_g for <p>I was trying to plot a field of normal vectors to a given implicit graph. What I got so far is: </p>
<pre><code>x, y = var('x y')
f(x,y) = 2*x*y^3
g(x,y) = x^2*3*y^2
d = plot_vector_field((f(x,y)/sqrt(f(x,y)^2+g(x,y)^2),g(x,y)/sqrt(f(x,y)^2+g(x,y)^2)), (x,-5,5), (y,-5,5))
s = implicit_plot(x^2*y^3-1 , (x,-5,5), (y,-5,5))
show(s+d)
</code></pre>
<p>And it works like a charm, however, is there a way to "restrict" a domain of plot_vector_field so it doesn't plot all the vectors in a given range, but only for point (x,y) lying on my graph? That is such points that x^2*y^3=1. I tried to just put it instead (y,-5,5) (in a y=(1/x^2)^(1/3) form), but it obviously doesn't work.
Thx for any help as I'm new to Sage.</p>
https://ask.sagemath.org/question/44207/restriction-of-domain-of-vector-field/?answer=44213#post-id-44213A solution is to transform the implicit graph into a curve and to use the method `along` of vector fields:
E.<x,y> = EuclideanSpace()
f(x,y) = 2*x*y^3
g(x,y) = x^2*3*y^2
v = E.vector_field([f(x,y)/sqrt(f(x,y)^2+g(x,y)^2),
g(x,y)/sqrt(f(x,y)^2+g(x,y)^2)])
t = var('t')
S = E.curve([t^3, t^(-2)], t)
vS = v.along(S)
graph = S.plot(prange=(-1.7, 1.7))
graph += vS.plot(E.cartesian_coordinates(), ranges={t: (-1.71, 1.7)},
number_values=25)
show(graph, ymax=5)
![image description](/upfiles/15415747936153798.png)
See [this page](https://sagemanifolds.obspm.fr/vector_calculus.html) for help/tutorials on vector fields with Sage.Wed, 07 Nov 2018 08:14:12 +0100https://ask.sagemath.org/question/44207/restriction-of-domain-of-vector-field/?answer=44213#post-id-44213Comment by MichaĆ_Fabisiak for <p>A solution is to transform the implicit graph into a curve and to use the method <code>along</code> of vector fields:</p>
<pre><code>E.<x,y> = EuclideanSpace()
f(x,y) = 2*x*y^3
g(x,y) = x^2*3*y^2
v = E.vector_field([f(x,y)/sqrt(f(x,y)^2+g(x,y)^2),
g(x,y)/sqrt(f(x,y)^2+g(x,y)^2)])
t = var('t')
S = E.curve([t^3, t^(-2)], t)
vS = v.along(S)
graph = S.plot(prange=(-1.7, 1.7))
graph += vS.plot(E.cartesian_coordinates(), ranges={t: (-1.71, 1.7)},
number_values=25)
show(graph, ymax=5)
</code></pre>
<p><img alt="image description" src="/upfiles/15415747936153798.png"></p>
<p>See <a href="https://sagemanifolds.obspm.fr/vector_calculus.html">this page</a> for help/tutorials on vector fields with Sage.</p>
https://ask.sagemath.org/question/44207/restriction-of-domain-of-vector-field/?comment=44228#post-id-44228Thanks for your help!Thu, 08 Nov 2018 19:01:11 +0100https://ask.sagemath.org/question/44207/restriction-of-domain-of-vector-field/?comment=44228#post-id-44228