Changeset 7903:439e75ca1c61
- Timestamp:
- 01/01/08 02:24:35 (5 years ago)
- Branch:
- default
- Location:
- sage
- Files:
-
- 4 edited
-
plot/plot3d/parametric_plot3d.py (modified) (5 diffs)
-
rings/polynomial/polynomial_element.pyx (modified) (1 diff)
-
server/notebook/cell.py (modified) (1 diff)
-
server/notebook/js.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/plot/plot3d/parametric_plot3d.py
r7902 r7903 45 45 We demonstrate each of the four ways to call this function. 46 46 47 1. A space curve defined by three functions of 1 variable: 48 sage: show(parametric_plot3d( (sin, cos, lambda u: u/10), (0, 20))) 49 50 Note above the lambda function, which creates a callable Python function 51 that sends u to u/10. 52 53 2. Next we draw the same plot as above, but using symbolic functions: 54 sage: var('u') 55 sage: show(parametric_plot3d( (sin(u), cos(u), u/10), (u, 0, 20))) 56 57 3. We draw a parametric surface using 3 Python functions (defined using 58 lambda): 47 1. A space curve defined by three functions of 1 variable: 48 sage: show(parametric_plot3d( (sin, cos, lambda u: u/10), (0, 20))) 49 50 Note above the lambda function, which creates a callable Python function 51 that sends u to u/10. 52 53 2. Next we draw the same plot as above, but using symbolic functions: 54 sage: var('u') 55 sage: show(parametric_plot3d( (sin(u), cos(u), u/10), (u, 0, 20))) 56 57 3. We draw a parametric surface using 3 Python functions (defined using 58 lambda): 59 sage: f = (lambda u,v: cos(u), lambda u,v: sin(u)+cos(v), lambda u,v: sin(v)) 60 sage: show(parametric_plot3d(f, (0, 2*pi), (-pi, pi))) 61 62 4. The same surface, but where the defining functions are symbolic: 63 sage: var('u,v') 64 sage: show(parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, 2*pi), (v, -pi, pi))) 65 66 We call the space curve function but with polynomials instead of 67 symbolic variables. 68 69 sage: R.<t> = RDF[] 70 sage: show(parametric_plot3d( (t, t^2, t^3), (t, 0, 3) ) ) 59 71 60 61 4. The same surface, but where the defining functions are symbolic: 62 sage: var('u,v') 63 sage: show(parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, 2*pi), (v, -pi, pi))) 72 Next we plot the same curve, but because we use (0, 3) instead of (t, 0, 3), 73 each polynomial is viewed as a callable function of one variable: 74 75 sage: show(parametric_plot3d( (t, t^2, t^3), (0, 3) ) ) 76 77 We do a plot but mix a symbolic input, and an integer: 78 sage: var('t') 79 sage: show(parametric_plot3d( (1, sin(t), cos(t)), (t, 0, 3) ) ) 80 81 We plot two interlinked tori: 82 sage: f1 = (4+(3+cos(v))*sin(u), 4+(3+cos(v))*cos(u), 4+sin(v)) 83 sage: f2 = (8+(3+cos(v))*cos(u), 3+sin(v), 4+(3+cos(v))*sin(u)) 84 sage: p1 = parametric_plot3d(f1, (u,0,2*pi), (v,0,2*pi), texture="red") 85 sage: p2 = parametric_plot3d(f2, (u,0,2*pi), (v,0,2*pi), texture="blue") 86 sage: show(p1 + p2) 64 87 """ 65 88 # TODO: … … 102 125 fail = 0 103 126 104 f_x, f_y, f_z = f105 127 if u is None: 128 f_x, f_y, f_z = f 106 129 for t in vals: 107 130 try: … … 110 133 fail += 1 111 134 else: 135 f_x, f_y, f_z = [ensure_subs(m) for m in f] 112 136 for t in vals: 113 137 try: 114 w.append((float(f_x.subs titute({u:t})), float(f_y.substitute({u:t})),115 float(f_z.subs titute({u:t}))))138 w.append((float(f_x.subs({u:t})), float(f_y.subs({u:t})), 139 float(f_z.subs({u:t})))) 116 140 except TypeError: 117 141 fail += 1 142 118 143 if fail > 0: 119 144 print "WARNING: Failed to evaluate parametric plot at %s points"%fail … … 136 161 if v is None: 137 162 raise ValueError, "both ranges must specify a variable or neither must" 138 f0, f1, f2 = f163 f0, f1, f2 = [ensure_subs(w) for w in f] 139 164 def f_x(uu,vv): 140 return float(f0.subs titute({u:uu, v:vv}))165 return float(f0.subs({u:uu, v:vv})) 141 166 def f_y(uu,vv): 142 return float(f1.subs titute({u:uu, v:vv}))167 return float(f1.subs({u:uu, v:vv})) 143 168 def f_z(uu,vv): 144 return float(f2.subs titute({u:uu, v:vv}))169 return float(f2.subs({u:uu, v:vv})) 145 170 146 171 def g(x,y): … … 191 216 v.append(b) 192 217 return v 218 219 220 def ensure_subs(f): 221 if not hasattr(f, 'subs'): 222 from sage.calculus.all import SR 223 return SR(f) 224 return f -
sage/rings/polynomial/polynomial_element.pyx
r7618 r7903 260 260 sage: f.subs(5) 261 261 127 262 """ 262 sage: f.subs({x:2}) 263 7 264 sage: f.subs({}) 265 x^3 + x - 3 266 sage: f.subs({'x':2}) 267 Traceback (most recent call last): 268 ... 269 TypeError: keys do not match self's parent 270 """ 271 if len(x) == 1 and isinstance(x[0], dict): 272 g = self.parent().gen() 273 if x[0].has_key(g): 274 return self(x[0][g]) 275 elif len(x[0]) > 0: 276 raise TypeError, "keys do not match self's parent" 277 return self 263 278 return self.__call__(*x, **kwds) 264 279 -
sage/server/notebook/cell.py
r7902 r7903 601 601 else: 602 602 size = 200 603 popup = """<br><a href="javascript:jmol_popup('%s');">Enlarge 3d View</a>"""%url603 popup = """<br><a href="javascript:jmol_popup('%s');">Enlarge</a>"""%url 604 604 script = '<script>jmol_applet(%s, "%s");</script>%s' % (size, url, popup) 605 605 images.append(script) -
sage/server/notebook/js.py
r7902 r7903 46 46 47 47 function jmol_popup(url) { 48 win = window.open ("", url, "width=400,height=400,resizable=1"); 48 win = window.open ("", "jmol viewer", "width=400,height=400,resizable=1,statusbar=0"); 49 win.document.body.innerHTML = ""; 50 win.document.title = "Sage 3d Viewer"; 51 win.document.writeln("<h1 align=center>Sage 3d Viewer</h1>"); 49 52 jmolSetDocument(win.document); 50 53 jmolApplet("100%", "script" + url); 54 win.focus(); 51 55 } 52 56 """ … … 821 825 window.open ("/history", 822 826 "", "menubar=1,scrollbars=1,width=800,height=600, toolbar=1,resizable=1"); 823 824 827 } 825 828
Note: See TracChangeset
for help on using the changeset viewer.
