Author: Juan Carlos Bustamante
Views : 59
Compute Environment: Ubuntu 18.04 (Deprecated)
typeset_mode(True)


## Exercice n. 28, section 1.1

var('x,y')
f(x,y)=sqrt(16-x^2 - 16 * y ^2)
contour_plot(f,(x,-4,4),(y,-1,1), colorbar=True)


($\displaystyle x$, $\displaystyle y$) ## Exercice n. 9, section 1.2

var('x,y')
f(x,y) = y^4/(x^4+3*y^4)
contour_plot(f,(x,-1,1),(y,-1,1), colorbar=True)

($\displaystyle x$, $\displaystyle y$) ## Exercice n. 39, section 1.2

var('x,y')
f(x,y) = x*y /(x^2 +x*y+y^2)
contour_plot(f,(x,-1,1),(y,-1,1), colorbar = True)

($\displaystyle x$, $\displaystyle y$) %md
## Exercice n. 94. section 2.1

Il faut définir


## Exercice n. 94. section 2.1



def f(x,y) :
if (x!=0)&(y!=0) :
return (x^3*y-x*y^3)/(x**2+y**2)
else :
return 0


f(0,0)

$\displaystyle 0$

cmsel = [colormaps['autumn'](i) for i in sxrange(0,1,0.05)]
S = plot3d(f,(x,-1,1),(y,-1,1), adaptive=True, color = cmsel)
S.show()


3D rendering not yet implemented
diff(f,x).factor()
diff(f,y).factor()



(x**2+y**2contour_plot?

/ext/sage/sage-8.0/local/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py:46: DeprecationWarning: OpenSSL.rand is deprecated - you should use os.urandom instead import OpenSSL.SSL
File: /ext/sage/sage-8.0/local/lib/python2.7/site-packages/sage/misc/decorators.py
Signature : contour_plot(f, xrange, yrange, axes=False, linestyles=None, region=None, labels=False, plot_points=100, linewidths=None, colorbar=False, contours=None, aspect_ratio=1, legend_label=None, frame=True, fill=True, label_inline=None, label_fmt='%1.2f', label_fontsize=9, label_colors='blue', label_inline_spacing=3, colorbar_spacing=None, colorbar_orientation='vertical', colorbar_format=None, **kwds)
Docstring :
"contour_plot" takes a function of two variables, f(x,y) and plots
contour lines of the function over the specified "xrange" and
"yrange" as demonstrated below.

"contour_plot(f, (xmin,xmax), (ymin,ymax), ...)"

INPUT:

* "f" -- a function of two variables

* "(xmin,xmax)" -- 2-tuple, the range of "x" values OR 3-tuple
"(x,xmin,xmax)"

* "(ymin,ymax)" -- 2-tuple, the range of "y" values OR 3-tuple
"(y,ymin,ymax)"

The following inputs must all be passed in as named parameters:

* "plot_points"  -- integer (default: 100); number of points to
plot in each direction of the grid.  For old computers, 25 is
fine, but should not be used to verify specific intersection
points.

* "fill" -- bool (default: "True"), whether to color in the area
between contour lines

* "cmap" -- a colormap (default: "'gray'"), the name of a
predefined colormap, a list of colors or an instance of a
matplotlib Colormap. Type: "import matplotlib.cm;

* "contours" -- integer or list of numbers (default: "None"): If
a list of numbers is given, then this specifies the contour
levels to use.  If an integer is given, then this many contour
lines are used, but the exact levels are determined
automatically. If "None" is passed (or the option is not given),
then the number of contour lines is determined automatically, and

* "linewidths" -- integer or list of integer (default: None), if
a single integer all levels will be of the width given, otherwise
the levels will be plotted with the width in the order given.  If
the list is shorter than the number of contours, then the widths
will be repeated cyclically.

* "linestyles" -- string or list of strings (default: None), the
style of the lines to be plotted, one of: ""solid"", ""dashed"",
""dashdot"", ""dotted"", respectively ""-"", ""--"", ""-."",
"":"".  If the list is shorter than the number of contours, then
the styles will be repeated cyclically.

* "labels" -- boolean (default: False) Show level labels or not.

The following options are to adjust the style and placement of
labels, they have no effect if no labels are shown.

* "label_fontsize" -- integer (default: 9), the font size of
the labels.

* "label_colors" -- string or sequence of colors (default:
None) If a string, gives the name of a single color with which
to draw all labels.  If a sequence, gives the colors of the
labels.  A color is a string giving the name of one or a
3-tuple of floats.

* "label_inline" -- boolean (default: False if fill is True,
otherwise True), controls whether the underlying contour is
removed or not.

* "label_inline_spacing" -- integer (default: 3), When inline,
this is the amount of contour that is removed from each side,
in pixels.

* "label_fmt" -- a format string (default: "%1.2f"), this is
used to get the label text from the level.  This can also be a
dictionary with the contour levels as keys and corresponding
text string labels as values.  It can also be any callable
which returns a string when called with a numeric contour
level.

* "colorbar" -- boolean (default: False) Show a colorbar or not.

The following options are to adjust the style and placement of
colorbars.  They have no effect if a colorbar is not shown.

* "colorbar_orientation" -- string (default: 'vertical'),
controls placement of the colorbar, can be either 'vertical' or
'horizontal'

* "colorbar_format" -- a format string, this is used to format
the colorbar labels.

* "colorbar_spacing" -- string (default: 'proportional').  If
'proportional', make the contour divisions proportional to
values.  If 'uniform', space the colorbar divisions uniformly,
without regard for numeric values.

* "legend_label" -- the label for this item in the legend

* "region" - (default: None) If region is given, it must be a
function

of two variables. Only segments of the surface where
region(x,y) returns a number >0 will be included in the plot.

EXAMPLES:

Here we plot a simple function of two variables.  Note that since
the input function is an expression, we need to explicitly declare
the variables in 3-tuples for the range:

sage: x,y = var('x,y')
sage: contour_plot(cos(x^2 + y^2), (x,-4,4), (y,-4,4))
Graphics object consisting of 1 graphics primitive

Here we change the ranges and add some options:

sage: x,y = var('x,y')
sage: contour_plot((x^2) * cos(x*y), (x,-10,5), (y,-5,5), fill=False, plot_points=150)
Graphics object consisting of 1 graphics primitive

An even more complicated plot:

sage: x,y = var('x,y')
sage: contour_plot(sin(x^2+y^2) * cos(x) * sin(y), (x,-4,4), (y,-4,4), plot_points=150)
Graphics object consisting of 1 graphics primitive

Some elliptic curves, but with symbolic endpoints.  In the first
example, the plot is rotated 90 degrees because we switch the
variables x, y:

sage: x,y = var('x,y')
sage: contour_plot(y^2 + 1 - x^3 - x, (y,-pi,pi), (x,-pi,pi))
Graphics object consisting of 1 graphics primitive

sage: contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi))
Graphics object consisting of 1 graphics primitive

We can play with the contour levels:

sage: x,y = var('x,y')
sage: f(x,y) = x^2 + y^2
sage: contour_plot(f, (-2,2), (-2,2))
Graphics object consisting of 1 graphics primitive

sage: contour_plot(f, (-2,2), (-2,2), contours=2, cmap=[(1,0,0), (0,1,0), (0,0,1)])
Graphics object consisting of 1 graphics primitive

sage: contour_plot(f, (-2,2), (-2,2),
....:              contours=(0.1,1.0,1.2,1.4), cmap='hsv')
Graphics object consisting of 1 graphics primitive

sage: contour_plot(f, (-2,2), (-2,2), contours=(1.0,), fill=False)
Graphics object consisting of 1 graphics primitive

sage: contour_plot(x - y^2, (x,-5,5), (y,-3,3), contours=[-4,0,1])
Graphics object consisting of 1 graphics primitive

We can change the style of the lines:

sage: contour_plot(f, (-2,2), (-2,2), fill=False, linewidths=10)
Graphics object consisting of 1 graphics primitive

sage: contour_plot(f, (-2,2), (-2,2), fill=False, linestyles='dashdot')
Graphics object consisting of 1 graphics primitive

sage: P = contour_plot(x^2 - y^2, (x,-3,3), (y,-3,3),
....:                  contours=[0,1,2,3,4], linewidths=[1,5],
....:                  linestyles=['solid','dashed'], fill=False)
sage: P
Graphics object consisting of 1 graphics primitive

sage: P = contour_plot(x^2 - y^2, (x,-3,3), (y,-3,3),
....:                  contours=[0,1,2,3,4], linewidths=[1,5],
....:                  linestyles=['solid','dashed'])
sage: P
Graphics object consisting of 1 graphics primitive

sage: P = contour_plot(x^2 - y^2, (x,-3,3), (y,-3,3),
....:                  contours=[0,1,2,3,4], linewidths=[1,5],
....:                  linestyles=['-',':'])
sage: P
Graphics object consisting of 1 graphics primitive

We can add labels and play with them:

sage: contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi),
....:              fill=False, cmap='hsv', labels=True)
Graphics object consisting of 1 graphics primitive

sage: P=contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi),
....:                fill=False, cmap='hsv',
....:                labels=True, label_fmt="%1.0f",
....:                label_colors='black')
sage: P
Graphics object consisting of 1 graphics primitive

sage: P = contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi),
....:                  fill=False, cmap='hsv', labels=True,
....:                  contours=[-4,0,4],
....:                  label_fmt={-4:"low", 0:"medium", 4: "hi"},
....:                  label_colors='black')
sage: P
Graphics object consisting of 1 graphics primitive

sage: P = contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi),
....:                fill=False, cmap='hsv', labels=True,
....:                contours=[-4,0,4], label_fmt=lambda x: "$z=%s$"%x,
....:                label_colors='black', label_inline=True,
....:                label_fontsize=12)
sage: P
Graphics object consisting of 1 graphics primitive

sage: P = contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi),
....:                  fill=False, cmap='hsv', labels=True,
....:                  label_fontsize=18)
sage: P
Graphics object consisting of 1 graphics primitive

sage: P = contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi),
....:                fill=False, cmap='hsv', labels=True,
....:                label_inline_spacing=1)
sage: P
Graphics object consisting of 1 graphics primitive

sage: P = contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi),
....:                  fill=False, cmap='hsv', labels=True,
....:                  label_inline=False)
sage: P
Graphics object consisting of 1 graphics primitive

We can change the color of the labels if so desired:

sage: contour_plot(f, (-2,2), (-2,2), labels=True, label_colors='red')
Graphics object consisting of 1 graphics primitive

We can add a colorbar as well:

sage: f(x, y)=x^2-y^2
sage: contour_plot(f, (x,-3,3), (y,-3,3), colorbar=True)
Graphics object consisting of 1 graphics primitive

sage: contour_plot(f, (x,-3,3), (y,-3,3), colorbar=True, colorbar_orientation='horizontal')
Graphics object consisting of 1 graphics primitive

sage: contour_plot(f, (x,-3,3), (y,-3,3), contours=[-2,-1,4], colorbar=True)
Graphics object consisting of 1 graphics primitive

sage: contour_plot(f, (x,-3,3), (y,-3,3), contours=[-2,-1,4],
....:              colorbar=True, colorbar_spacing='uniform')
Graphics object consisting of 1 graphics primitive

sage: contour_plot(f, (x,-3,3), (y,-3,3), contours=[0,2,3,6],
....:              colorbar=True, colorbar_format='%.3f')
Graphics object consisting of 1 graphics primitive

sage: contour_plot(f, (x,-3,3), (y,-3,3), labels=True,
....:              label_colors='red', contours=[0,2,3,6],
....:              colorbar=True)
Graphics object consisting of 1 graphics primitive

sage: contour_plot(f, (x,-3,3), (y,-3,3), cmap='winter',
....:              contours=20, fill=False, colorbar=True)
Graphics object consisting of 1 graphics primitive

This should plot concentric circles centered at the origin:

sage: x,y = var('x,y')
sage: contour_plot(x^2 + y^2-2,(x,-1,1), (y,-1,1))
Graphics object consisting of 1 graphics primitive

Extra options will get passed on to show(), as long as they are
valid:

sage: f(x,y) = cos(x) + sin(y)
sage: contour_plot(f, (0,pi), (0,pi), axes=True)
Graphics object consisting of 1 graphics primitive

sage: contour_plot(f, (0,pi), (0,pi)).show(axes=True) # These are equivalent

One can also plot over a reduced region:

sage: contour_plot(x**2 - y**2, (x,-2,2), (y,-2,2), region=x - y, plot_points=300)
Graphics object consisting of 1 graphics primitive

Note that with "fill=False" and grayscale contours, there is the
possibility of confusion between the contours and the axes, so use
"fill=False" together with "axes=True" with caution:

sage: contour_plot(f, (-pi,pi), (-pi,pi), fill=False, axes=True)
Graphics object consisting of 1 graphics primitive