Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168754
Image: ubuntu2004

Überschrift

das ist ein Text: sin(x2)=fsin(x^2)=f hier geht es weiter.

var('x y z a b s')
(x, y, z, a, b, s)
def f(x): return 3*sin(x) def g(x): return 1/3*sin(x)
f=3*sin(x) g=1/3*sin(x) pp=[(-1,-1),(-0.5,f(x=-0.5)),(3,1),(1,6)] k=0 k=plot(f,-1,8,color='red') k+=plot(g,-1,8,color='blue') k+=line(pp,color='green') k+=point(pp,color='black') k+=text('Hallo Hallo hier hier',(4.5,1)) k.show(axes=False)
l=[2,43,2,3,2,1,4.3,23,'hallo','hund']
plot3d?

File: /usr/local/sage2/local/lib/python2.6/site-packages/sage/plot/plot3d/plot3d.py

Type: <type ‘function’>

Definition: plot3d(f, urange, vrange, adaptive=False, transformation=None, **kwds)

Docstring:

INPUT:

  • f - a symbolic expression or function of 2 variables
  • urange - a 2-tuple (u_min, u_max) or a 3-tuple (u, u_min, u_max)
  • vrange - a 2-tuple (v_min, v_max) or a 3-tuple (v, v_min, v_max)
  • adaptive - (default: False) whether to use adaptive refinement to draw the plot (slower, but may look better). This option does NOT work in conjuction with a transformation (see below).
  • mesh - bool (default: False) whether to display mesh grid lines
  • dots - bool (default: False) whether to display dots at mesh grid points
  • plot_points - (default: “automatic”) initial number of sample points in each direction; an integer or a pair of integers
  • transformation - (default: None) a transformation to apply. May be a 3 or 4-tuple (x_func, y_func, z_func, independent_vars) where the first 3 items indicate a transformation to cartesian coordinates (from your coordinate system) in terms of u, v, and the function variable fvar (for which the value of f will be substituted). If a 3-tuple is specified, the independent variables are chosen from the range variables. If a 4-tuple is specified, the 4th element is a list of independent variables. transformation may also be a predefined coordinate system transformation like Spherical or Cylindrical.

Note

mesh and dots are not supported when using the Tachyon raytracer renderer.

EXAMPLES: We plot a 3d function defined as a Python function:

sage: plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2))

We plot the same 3d function but using adaptive refinement:

sage: plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2), adaptive=True)

Adaptive refinement but with more points:

sage: plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2), adaptive=True, initial_depth=5)

We plot some 3d symbolic functions:

sage: var('x,y')
(x, y)
sage: plot3d(x^2 + y^2, (x,-2,2), (y,-2,2))
sage: plot3d(sin(x*y), (x, -pi, pi), (y, -pi, pi))

We give a plot with extra sample points:

sage: var('x,y')
(x, y)
sage: plot3d(sin(x^2+y^2),(x,-5,5),(y,-5,5), plot_points=200)
sage: plot3d(sin(x^2+y^2),(x,-5,5),(y,-5,5), plot_points=[10,100])

A 3d plot with a mesh:

sage: var('x,y')
(x, y)
sage: plot3d(sin(x-y)*y*cos(x),(x,-3,3),(y,-3,3), mesh=True)

Two wobby translucent planes:

sage: x,y = var('x,y')
sage: P = plot3d(x+y+sin(x*y), (x,-10,10),(y,-10,10), opacity=0.87, color='blue')
sage: Q = plot3d(x-2*y-cos(x*y),(x,-10,10),(y,-10,10),opacity=0.3,color='red')
sage: P + Q

We draw two parametric surfaces and a transparent plane:

sage: L = plot3d(lambda x,y: 0, (-5,5), (-5,5), color="lightblue", opacity=0.8)
sage: P = plot3d(lambda x,y: 4 - x^3 - y^2, (-2,2), (-2,2), color='green')
sage: Q = plot3d(lambda x,y: x^3 + y^2 - 4, (-2,2), (-2,2), color='orange')
sage: L + P + Q

We draw the “Sinus” function (water ripple-like surface):

sage: x, y = var('x y')
sage: plot3d(sin(pi*(x^2+y^2))/2,(x,-1,1),(y,-1,1))

Hill and valley (flat surface with a bump and a dent):

sage: x, y = var('x y')
sage: plot3d( 4*x*exp(-x^2-y^2), (x,-2,2), (y,-2,2))

An example of a transformation:

sage: r, phi, z = var('r phi z')
sage: trans=(r*cos(phi),r*sin(phi),z)
sage: plot3d(cos(r),(r,0,17*pi/2),(phi,0,2*pi),transformation=trans,opacity=0.87).show(aspect_ratio=(1,1,2),frame=False)

Many more examples of transformations:

sage: u, v, w = var('u v w')
sage: rectangular=(u,v,w)
sage: spherical=(w*cos(u)*sin(v),w*sin(u)*sin(v),w*cos(v))
sage: cylindric_radial=(w*cos(u),w*sin(u),v)
sage: cylindric_axial=(v*cos(u),v*sin(u),w)
sage: parabolic_cylindrical=(w*v,(v^2-w^2)/2,u)

Plot a constant function of each of these to get an idea of what it does:

sage: A = plot3d(2,(u,-pi,pi),(v,0,pi),transformation=rectangular,plot_points=[100,100])
sage: B = plot3d(2,(u,-pi,pi),(v,0,pi),transformation=spherical,plot_points=[100,100])
sage: C = plot3d(2,(u,-pi,pi),(v,0,pi),transformation=cylindric_radial,plot_points=[100,100])
sage: D = plot3d(2,(u,-pi,pi),(v,0,pi),transformation=cylindric_axial,plot_points=[100,100])
sage: E = plot3d(2,(u,-pi,pi),(v,-pi,pi),transformation=parabolic_cylindrical,plot_points=[100,100])
sage: @interact
... def _(which_plot=[A,B,C,D,E]):
...       show(which_plot)
<html>...

Now plot a function:

sage: g=3+sin(4*u)/2+cos(4*v)/2
sage: F = plot3d(g,(u,-pi,pi),(v,0,pi),transformation=rectangular,plot_points=[100,100])
sage: G = plot3d(g,(u,-pi,pi),(v,0,pi),transformation=spherical,plot_points=[100,100])
sage: H = plot3d(g,(u,-pi,pi),(v,0,pi),transformation=cylindric_radial,plot_points=[100,100])
sage: I = plot3d(g,(u,-pi,pi),(v,0,pi),transformation=cylindric_axial,plot_points=[100,100])
sage: J = plot3d(g,(u,-pi,pi),(v,0,pi),transformation=parabolic_cylindrical,plot_points=[100,100])
sage: @interact
... def _(which_plot=[F, G, H, I, J]):
...       show(which_plot)
<html>...

TESTS:

Make sure the transformation plots work:

sage: show(A + B + C + D + E)
sage: show(F + G + H + I + J)

Listing the same plot variable twice gives an error:

sage: x, y = var('x y')
sage: plot3d( 4*x*exp(-x^2-y^2), (x,-2,2), (x,-2,2))
...
ValueError: range variables should be distinct, but there are duplicates
l[0]+l[6]
6.30000000000000
len(l)
10
l[0]
2
range(9)
[0, 1, 2, 3, 4, 5, 6, 7, 8]
l.append(67)
l
[2, 43, 2, 3, 2, 1, 4.30000000000000, 23, 'hallo', 'hund', 67]
l[5]
1
for i in range(len(l)-1): print l[i]
2 43 2 3 2 1 4.30000000000000 23 hallo hund
print g
1/3*sin(x)
pretty_print(g)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3} \, \sin\left(x\right)
p3p=plot3d(lambda x, y: x^2 + sin(y), (-2,2), (-2,7),figsize=4) p3p+=line3d([(-1,1,5),(2,2,2),(-1,0.3,7)],color='red',thickness=8) p3p.show()
line3d?

File: /usr/local/sage2/local/lib/python2.6/site-packages/sage/plot/plot3d/shapes2.py

Type: <type ‘function’>

Definition: line3d(points, thickness=1, radius=None, arrow_head=False, **kwds)

Docstring:

Draw a 3d line joining a sequence of points.

One may specify either a thickness or radius. If a thickness is specified, this line will have a constant diameter regardless of scaling and zooming. If a radius is specified, it will behave as a series of cylinders.

INPUT:

  • points - a list of at least 2 points
  • thickness - (default: 1)
  • radius - (default: None)
  • arrow_head - (default: False)
  • color - a word that describes a color
  • rgbcolor - (r,g,b) with r, g, b between 0 and 1 that describes a color
  • opacity - (default: 1) if less than 1 then is transparent

EXAMPLES:

A line in 3-space:

sage: line3d([(1,2,3), (1,0,-2), (3,1,4), (2,1,-2)])

The same line but red:

sage: line3d([(1,2,3), (1,0,-2), (3,1,4), (2,1,-2)], color='red')

A transparent thick green line and a little blue line:

sage: line3d([(0,0,0), (1,1,1), (1,0,2)], opacity=0.5, radius=0.1, \
             color='green') + line3d([(0,1,0), (1,0,2)])

A Dodecahedral complex of 5 tetrahedrons (a more elaborate examples from Peter Jipsen):

sage: def tetra(col):
...       return line3d([(0,0,1), (2*sqrt(2.)/3,0,-1./3), (-sqrt(2.)/3, sqrt(6.)/3,-1./3),\
...              (-sqrt(2.)/3,-sqrt(6.)/3,-1./3), (0,0,1), (-sqrt(2.)/3, sqrt(6.)/3,-1./3),\
...              (-sqrt(2.)/3,-sqrt(6.)/3,-1./3), (2*sqrt(2.)/3,0,-1./3)],\
...              color=col, thickness=10, aspect_ratio=[1,1,1])
...
sage: v  = (sqrt(5.)/2-5/6, 5/6*sqrt(3.)-sqrt(15.)/2, sqrt(5.)/3)
sage: t  = acos(sqrt(5.)/3)/2
sage: t1 = tetra('blue').rotateZ(t)
sage: t2 = tetra('red').rotateZ(t).rotate(v,2*pi/5)
sage: t3 = tetra('green').rotateZ(t).rotate(v,4*pi/5)
sage: t4 = tetra('yellow').rotateZ(t).rotate(v,6*pi/5)
sage: t5 = tetra('orange').rotateZ(t).rotate(v,8*pi/5)
sage: show(t1+t2+t3+t4+t5, frame=False)

TESTS:

Copies are made of the input list, so the input list does not change:

sage: mypoints = [vector([1,2,3]), vector([4,5,6])]
sage: type(mypoints[0])
<type 'sage.modules.vector_integer_dense.Vector_integer_dense'>
sage: L = line3d(mypoints)
sage: type(mypoints[0])
<type 'sage.modules.vector_integer_dense.Vector_integer_dense'>