ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 06 Nov 2018 14:04:40 -0600Restriction of domain of vector fieldhttp://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.Michał_FabisiakTue, 06 Nov 2018 14:04:40 -0600http://ask.sagemath.org/question/44207/implicit plot with different scales on x and y axeshttp://ask.sagemath.org/question/41110/implicit-plot-with-different-scales-on-x-and-y-axes/ Say I want to plot `implicit_plot(x^2 + 10000*y^2 - 2, (x,-3,3), (y,-0.03,0.03))`, or anything else where the interesting values of x and y varies over different orders of magnitude. At least on my machine, the result is a completely illegible png, squished into nothingness.
http: // i187.photobucket.com/albums/x207/pratarpersilja/scaling_unusable_zpsspbvecof.png
(I wasn't allowed to add clickable links).
Of course, in this particular case I could rewrite the expression manually until the x and y ranges are the same. In the case that inspired these experiments in the first place, that rewrite is not realistic to do by hand.
How do I force an implicit plot to not have the same number of pixels per numerical unit in x and y directions?pratarpersiljaTue, 13 Feb 2018 22:03:13 -0600http://ask.sagemath.org/question/41110/Using Sage plotting capability on data from PARI/GP (1)http://ask.sagemath.org/question/41048/using-sage-plotting-capability-on-data-from-parigp-1/ This is a short follow-up question from [this one](https://ask.sagemath.org/question/41029/using-sage-plotting-capability-on-data-from-parigp/).
I would like to produce an implicit plot (a contour plot where the real or imaginary values of a function are zero):
var('x,y,s')
g=real(zeta(s))
implicit_plot(lambda x,y:g(x+y*I),(x,-3,3),(y,-3,3))
This works fine, however I want to use GP/Pari to evaluate the zeta function and therefore wrote:
var('x,y')
g=gp("H(s)=zeta(s)")
implicit_plot(lambda x,y:real_part(g(x+y*I)),(x,-3,3),(y,-3,3))
but then keep getting an error message:
**PARI/GP ERROR:
*** at top-level: sage[45020]=sage[16][1]
*** ^---
*** incorrect type in _[_] OCcompo1 [not a vector] (t_REAL).**
For 'normal' plots like this one:
var('x')
g=gp("H(s)=real(zeta(s))")
plot(lambda x:(g(x)),(x,3,6))
the interface with GP works fine, so I probably do something wrong using multiple variables or complex numbers? It doesn't seem to be zeta-function specific (like the pole at s=1), since it also fails for e.g. the cos-function.
Grateful for any advice on how to make this work.
Thanks!RuudHFri, 09 Feb 2018 09:20:43 -0600http://ask.sagemath.org/question/41048/Add legend to implicit_plot for different parameter valueshttp://ask.sagemath.org/question/40277/add-legend-to-implicit_plot-for-different-parameter-values/Hi,
I want to add a legend to an implicit plot, to plot the same function for different parameter values. I can plot the functions but the legend is not displayed. Is it possible to do it?
var('x y z')
xrange = (x,0,2)
yrange = (y,0,2)
z=1
g1 = implicit_plot(x**3-2*x+y**2==z,xrange,yrange,color='red',legend_label='g1')
z=2
g2 = implicit_plot(x**3-2*x+y**2==z,xrange,yrange,color='blue',legend_label='g2')
g = g1+g2
g.legend(True)
g.show(legend_loc='upper right',frame=True)flucoeThu, 21 Dec 2017 17:54:19 -0600http://ask.sagemath.org/question/40277/Implicit plot with squaring and absolute value produces empty plothttp://ask.sagemath.org/question/38563/implicit-plot-with-squaring-and-absolute-value-produces-empty-plot/ The following code:
sage: x,y = var('x y')
sage: implicit_plot(x, (x,-2,2), (y,-2,2))
produces a plot of a straight line along the coordinate y-axis as expected (it should plot the curve $x = 0$).
However, this very similar code:
sage: implicit_plot(x^2, (x,-2,2), (y,-2,2))
produces a plot with nothing on it, even though it *should* plot the curve $x^2 = 0$ which is clearly the same as the above curve.
This problem seems to persist with any function $f(x, y)$, i.e., in the following code,
f(x, y) = [some expression involving x and y]
sage: implicit_plot(f(x, y), [x scale], [y scale])
sage: implicit_plot(f(x, y)^2, [x scale], [y scale])
the second line produces a nonempty plot while the third line produces an empty plot. Replacing `f(x,y)^2` with `abs(f(x,y))` or even `abs_symbolic(f(x,y))` has the same effect: they all produce empty plots.
The problem persists when one replaces `implicit_plot` with `implicit_plot3d`.
What's going on? Is this a bug?DoekeThu, 17 Aug 2017 17:36:31 -0500http://ask.sagemath.org/question/38563/X and Y values of plot points using implicit_plothttp://ask.sagemath.org/question/27249/x-and-y-values-of-plot-points-using-implicit_plot/ Is there a way to get Sage to generate a list of the x and y values computed in generating a 2D implicit plot using the implicit_plot command? Thanks.cltho2Thu, 02 Jul 2015 17:32:33 -0500http://ask.sagemath.org/question/27249/Plotting an element in a polynomial idealhttp://ask.sagemath.org/question/26931/plotting-an-element-in-a-polynomial-ideal/I have a polynomial ring in three variables:
P.<x,y,z> = PolynomialRing(QQ)
and I've eliminated the variable `t` in an ideal generated by several polynomials to obtain an implicit function in just `x` and `y`. I'd like to plot this function. But the `plot` method, applied to an ideal in just two variables, produces the error:
ValueError: Variable 't' not found
So either I need somehow to introduce this variable into the plot, or pull the function out of the polynomial ring so that it can be plotted as a function of real variables with `implicit_plot`. But I'm not sure how to do either...any advice would be most helpful!AlasdairSun, 24 May 2015 20:57:20 -0500http://ask.sagemath.org/question/26931/Implicit plot in tachyon scenehttp://ask.sagemath.org/question/26639/implicit-plot-in-tachyon-scene/Is there a way to get some implicit plot, or some other graphic object in general into a tachyon scene?
Something like:
t = Tachyon(xres=400,yres=400, camera_center=(4,30,30), look_at=(0,0,0))
t.ImplicitPlot3d( ... )
Or can I modify the camera_center parameter when using the tachyon viewer in the show() method?
ThorstenFri, 24 Apr 2015 12:37:52 -0500http://ask.sagemath.org/question/26639/convert function to variablehttp://ask.sagemath.org/question/23984/convert-function-to-variable/ Aloha,
I am solving differential equations using desolve, which requires that I declare my dependent variable, say y, as a function, but if I want to plot the result using implicit_plot or plot the slope field using plot_slope_field, then I need y to be a variable.
I have been able to do this by converting my function to a string, replacing "y(x)" by "y" and then converting the result back to a sage symbolic expression.
For example,
x = var('x')
y = function('y', x)
f=(4-2*x)/(3*y^2-5)
print(f)
y = var('y')
f=sage_eval(str(f).replace('y(x)','y'), locals=vars())
print(f)
prints
-2*(x - 2)/(3*y(x)^2 - 5)
-2*(x - 2)/(3*y^2 - 5)
An example with dsolve and implicit_plot:
# Define f(x,y)
x = var('x')
y = function('y', x)
f=(4-2*x)/(3*y^2-5)
# Define dy/dx=f(x,y)
de=diff(y,x)==f
# Solve dy/dx=f(x,y)
sol=desolve(de,y,ics=(1,3))
show(sol)
# Convert our solution to something that implicit_plot can handle,
# i.e., change y fom a function to a variable
y = var('y')
sol=sage_eval(str(sol).replace('y(x)','y'), locals=vars())
implicit_plot(sol, (x,-6,8), (y,-6,6))
I then wrote a function that does this:
def convert_function_to_var(f) :
x,y = var('x,y')
f=sage_eval(str(f).replace('y(x)','y'), locals=vars())
return f
which I test this way
x = var('x')
y = function('y', x)
f=(4-2*x)/(3*y^2-5)
print(f)
f=convert_function_to_var(f)
print(f)
Now, my questions are
1. is there a better way to do
this?
2. when I define
`convert_function_to_var` why do I
need to declare `x,y = var('x,y')`
in the procedure?
3. `convert_function_to_var` requires
that I have two, and only two,
variables, named x and y, is there
some more generic and robust way of
doing this?
Mahalo,
RamónRamón Figueroa-CentenoFri, 29 Aug 2014 10:39:49 -0500http://ask.sagemath.org/question/23984/Sage plot inner structurehttp://ask.sagemath.org/question/8168/sage-plot-inner-structure/Hi, I would like to manipulate the raw data of a plot. More specifically, I'd like to get the set of points produced by implicit_plot in order to use it for another task.
Is that possible?jllbWed, 11 Dec 2013 20:45:49 -0600http://ask.sagemath.org/question/8168/Implicit plotting accuracyhttp://ask.sagemath.org/question/10770/implicit-plotting-accuracy/I am trying to plot this implicit function
![image description](http://www.xamuel.com/blog/wp-content/uploads/5.jpg)
What I get is
![image description](http://www.sagenb.org/home/aspras/1/cells/20/sage0.png)
Is there a way to make the curves thinner ?asprasSat, 23 Nov 2013 05:01:36 -0600http://ask.sagemath.org/question/10770/get_minmax_data on implicit_plothttp://ask.sagemath.org/question/7920/get_minmax_data-on-implicit_plot/This is a sequel of [my question about plotting level set](http://ask.sagemath.org/question/358/plot-the-level-sets-of-a-function).
In the following, G is a circle :
sage: f(x,y)=x**2+y**2
sage: G=implicit_plot(f==1,(x,-2,2),(y,-3,3))
sage: G.get_minmax_data()
{'xmin': -2.0, 'ymin': -3.0, 'ymax': 3.0, 'xmax': 2.0}
The "correct" get_minmax_data sould be
{'xmin': -1.0, 'ymin': -1.0, 'ymax': 1.0, 'xmax': 1.0}
As far as I understood the code (and the thread "Retrieving xy data from implicit plots" on Sage-support), the following is the relevant part :
xy_data_arrays = numpy.asarray([[[func(x, y) for x in xsrange(*ranges[0],include_endpoint=True)]
for y in xsrange(*ranges[1], include_endpoint=True)]
for func in g],dtype=float)
in ../plot/contour_plot.py
My questions are :
1. can I retrieve that xy_data_array ?
2. If I analyse xy_data_array, I suppose that extracting the point with lowest x-component such that the value is positive will provide me the "correct" xmin of the plot. I'm wrong ?
Laurent ClaessensFri, 04 Feb 2011 06:21:09 -0600http://ask.sagemath.org/question/7920/Plot the level sets of a functionhttp://ask.sagemath.org/question/7919/plot-the-level-sets-of-a-function/I'm trying to draw level set of a function f:R^2->R, that is the set of solutions of
f(x,y)=h for a given h.
For that purpose I wrote the following
#! /usr/bin/sage -python
# -*- coding: utf8 -*-
from sage.all import *
def level_curve(f,h):
solutions_list = solve(f==h,y)
return [sol.rhs() for sol in solutions_list]
var('x,y')
f=x+y+2
for g in level_curve(f,3):
print g
print "-----"
f=x**2+y**2
for g in level_curve(f,3):
print g
This works, but I'm not satisfied principally because I got the level sets under the form of a list of functions. Moreover it will not work if the level set is vertical.
Thus I would prefer to get the solution under the form of a parametric curve.
Does Sage provides something for that ?
Laurent ClaessensThu, 03 Feb 2011 23:20:26 -0600http://ask.sagemath.org/question/7919/