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.Sun, 11 Oct 2015 04:19:07 +0200Plotting families (depending on integer parameter(s)) of curvilinear coordinate and isolevel lines and surfaces, resp. for functional and parametric surfaces, and for 3-variate scalar fields and volume deformations in 3Dhttps://ask.sagemath.org/question/29836/plotting-families-depending-on-integer-parameters-of-curvilinear-coordinate-and-isolevel-lines-and-surfaces-resp-for-functional-and-parametric/To begin with a warning: I am a very experienced mathematician but a complete – 'greenhorn' – beginner in SAGE.
I would like to be able to plot in the same 3D plot FAMILIES OF PARAMETRIC CURVES IN 3D (x(i)=x(t,i),y=y(t,i),z=z(t,i)) plotted via e.g. parametric_plot3D DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i in range(I+1) where the coordinate functions x,y,z are defined as functions of t by me and are not necessarily predefined SAGE functions, and where I can vary the non-negative integer I without varying the code.
I would like to do the same for FAMILIES OF FUNCTIONAL SURFACES (z=f(x,y,i), DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i) using e.g. ParametricSurface, as well as TO DO THE SAME for FAMILIES OF PARAMETRIC SURFACES ( (fx(u,v,i),fy(u,v,i),fz(u,v,i)) ) via using e.g. parametric_plot3D DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i in range(I+1.
I would also like to be able to do the same for FAMILIES OF IMPLICITLY DEFINED SURFACES IN 3D DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i, using e.g. implicit_plot3d ( (f(x,y,z)-C(i)==0, I in range (I+1)), C being a 1-dimensional array (in general algorithmic language) with entries – real numbers in the range of the values of the real-valued f), with the possibility of custom definition of f, I and C.
Examining the SAGE tutorials and reference manuals, I have so far been able to find a model solution of this problem only for planar curves in 2D using plot() and only for SAGE-predefined curves (namely, polynomial curves):
http://sage.maa.org/home/pub/140/
sage: lotsa_plots = sum([plot(x^n,(x,0,1),color=rainbow(5)[n]) for n in range(5)])
Already in this simple 2D case, if the SAGE-predefined function x^n in the above example be replaced by a custom-defined function f(x,n) , it is not clear to me (a greenhorn!) how to extend the above instance to plotting together the 2D graphs of f(x,n), color=rainbow(N)[n]) for n in range(N), where one should be able to vary N withouth modifying the SAGE code.
I think that providing examples solving the above tasks in the SAGE tutorials/manuals (or developing SAGE in this direction if the tasks are currently SAGE-unsolvable!) is of key importance FOR A GREAT MANY OF THE USERS (OR WANNABE USERS) OF SAGE WHO ARE EXPERIENCED THEORETICIANS BUT ARE NOT EXPERIENCED PROGRAMMERS.
To facilitate the eventual answering of these questions, I herewith propose a simple but comprehensive example. IF YOU PROVIDE COMPLETE ANSWERS CONCERNING THIS EXAMPLE, YOU WILL HAVE ANSWERED ALL OF THE ABOVE QUESTIONS TOGETHER. Moreover, your answer would certainly merit to be included among the examples in the next version(s) of the SAGE tutorial[(s) and/or reference manual(s).
Consider the 3D scalar field (argument is a 3D vector, value is a real scalar between 0 and 1)
F(x,y,z)=exp(-x^2)*((cos(pi*y))^2)*(1/(1+z^2)), -1<=x,y,z<=1
Design a 3D-plot of F (different from ray tracing a grey-scale colored 3D point cloud and different from constructing and plotting several isosurfaces), namely, by using the
Curvilinear coordinates in 3D induced by F:
Consider the positive integers l,m,n and knots
-1==x_0<x_1<...<x_l==1,
-1==y_0<y_1<...<y_m==1,
-1==z_0<x_1<...<x_n==1.
Plot in 3D:
the x-coordinate lines F(x,y_j,z_k), j in range(m+1), k in range(n+1), rgbcolor=(1,0,0), thickness=3;
the y-coordinate lines F(x_i,y,z_k), i in range(l+1), k in range(n+1), rgbcolor=(0,1,0), thickness=3;
the z-coordinate lines F(x_i,y_j,z), j in range(m+1), k in range(n+1), rgbcolor=(0,0,1), thickness=3;
the (x,y)-coordinate surfaces F(x,y,z_k), k in range(n+1), rgbcolor=(1/2,1/2,0), opacity=0.5;
the (y,z)-coordinate surfaces F(x_i,y,z), i in range(l+1), rgbcolor=(0,1/2,1/2), opacity=0.5;
the (x,z)-coordinate surfaces F(x,y_j,z), j in range(m+1), rgbcolor=(1/2,0,1/2), opacity=0.5;
in a common plot P (equal to the sum of the plots of the separate coordinate lines and surfaces as described above), and then execute the SAGE command
P.show(viewer='jmol')
where l,m,n can be varied as input WITHOUT otherwise CHANGING THE SAGE CODE of the plotting.
Analogously, of interest is an isolevel/isosurface plot of F, as follows:
Consider the positive integer J and the knots
0==c_0<x_1<...<c_K==1, where [0,1] is the range of values taken by F.
Plot in 3D the isolevel surfaces (isosurfaces)
F(x,y,z)-c_I=0, I in range(K+1), color=rainbow(K)[I] , opacity=0.5
using (A) the default implicit_plot3d method and (B) the 'smooth-triangle' method for Tachyon (the normals are very easy to compute),
then sum the plots into P and execute again
P.show(viewer='jmol')
So far I can only plot and visualize (with my preferences being to use jmol for the latter) single 3D-curves (via parametric_plot3d), single functional surfaces (via ParametricSurface) and single parametric surfaces (via parametric_plot3d), as well as single implicitly defined surfaces (via implicit_plot3d) but so far my efforts to organize loops in i,j,k and I to plot the above-sai 3d-geometric objects in a common plot have failed.
Typically, in an algorithmic language one would organize the data about the plotting of a single x-coordinate line in a 2-dimensional array Plinex(j,k) using parametric_plot3d for the design of every entry in the array, and then it should be possible to execute something of the type
P=sum(Plinex(j,k), j in range(m+1), k in range(n+1))
Analogously, in this hypothetical algorithmic language the data about the plotting of a single (x,y)-coordinate surface should be organized in a 1-dimensional array Psurfxy(k) using ParametricSurface for the design of every entry in the array, and then it should be possible to execute something of the type
P=sum(Psurfxy(k), k in range(n+1))
Also analogously, one should be able to organize the data about the plotting of a single isosurface in a 1-dimensional array Pisosurf(I) using implicit_plot3d (in each of the variants A and B considered above, or at least in variant A only) for the design of every entry in the array, and then it should be possible to execute something of the type
P=sum(Pisosurf(I), I in range(K+1))
The only case mentioned in the title which this example does not cover is the case of plotting curvilinear curves and surfaces for a PARAMETRIC VOLUME DEFORMATION (i.e., (x=fx(u,v,w),y=fy(u,v,w),z=fz(u,v,w)) where (u,v,w) belongs to 3-VARIATE parametric domain), but handling this case would be an easy consequence of the case of a scalar field F(x,y,z) considered above.
Unfortunately, being a newbie in SAGE, I do not know how to write all this in SAGE.
CAN YOU PLEASE HELP WITH THIS? MANY PEOPLE WOULD BE THANKFUL FOR YOUR REPLY, I am sure...Thu, 08 Oct 2015 16:22:59 +0200https://ask.sagemath.org/question/29836/plotting-families-depending-on-integer-parameters-of-curvilinear-coordinate-and-isolevel-lines-and-surfaces-resp-for-functional-and-parametric/Comment by fidbc for <div class="snippet"><p>To begin with a warning: I am a very experienced mathematician but a complete – 'greenhorn' – beginner in SAGE.
I would like to be able to plot in the same 3D plot FAMILIES OF PARAMETRIC CURVES IN 3D (x(i)=x(t,i),y=y(t,i),z=z(t,i)) plotted via e.g. parametric_plot3D DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i in range(I+1) where the coordinate functions x,y,z are defined as functions of t by me and are not necessarily predefined SAGE functions, and where I can vary the non-negative integer I without varying the code.
I would like to do the same for FAMILIES OF FUNCTIONAL SURFACES (z=f(x,y,i), DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i) using e.g. ParametricSurface, as well as TO DO THE SAME for FAMILIES OF PARAMETRIC SURFACES ( (fx(u,v,i),fy(u,v,i),fz(u,v,i)) ) via using e.g. parametric_plot3D DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i in range(I+1.
I would also like to be able to do the same for FAMILIES OF IMPLICITLY DEFINED SURFACES IN 3D DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i, using e.g. implicit_plot3d ( (f(x,y,z)-C(i)==0, I in range (I+1)), C being a 1-dimensional array (in general algorithmic language) with entries – real numbers in the range of the values of the real-valued f), with the possibility of custom definition of f, I and C.
Examining the SAGE tutorials and reference manuals, I have so far been able to find a model solution of this problem only for planar curves in 2D using plot() and only for SAGE-predefined curves (namely, polynomial curves):
<a href="http://sage.maa.org/home/pub/140/">http://sage.maa.org/home/pub/140/</a> </p>
<p>sage: lotsa_plots = sum([plot(x^n,(x,0,1),color=rainbow(5)[n]) for n in range(5)])
Already in this simple 2D case, if the SAGE-predefined function x^n in the above example be replaced by a custom-defined function f(x,n) , it is not clear to me (a greenhorn!) how to extend the above instance to plotting together the 2D graphs of f(x,n), color=rainbow(N)[n]) for n in range(N), where one should be able to vary N withouth modifying the SAGE code.
I think that providing examples solving the above tasks in the SAGE tutorials/manuals (or developing SAGE in this direction if the tasks are currently SAGE-unsolvable!) is of key importance FOR A GREAT MANY OF THE USERS (OR WANNABE USERS) OF SAGE WHO ARE EXPERIENCED THEORETICIANS BUT ARE NOT EXPERIENCED PROGRAMMERS.
To facilitate the eventual answering of these questions, I herewith propose a simple but comprehensive example. IF YOU PROVIDE COMPLETE ANSWERS CONCERNING THIS EXAMPLE, YOU WILL HAVE ANSWERED ALL OF THE ABOVE QUESTIONS TOGETHER. Moreover, your answer would certainly merit to be included among the examples in the next version(s) of the SAGE tutorial[(s) and/or reference manual(s). <br/>
Consider the 3D scalar field (argument is a 3D vector ...</br/><span class="expander"> <a>(more)</a></span></p></div>https://ask.sagemath.org/question/29836/plotting-families-depending-on-integer-parameters-of-curvilinear-coordinate-and-isolevel-lines-and-surfaces-resp-for-functional-and-parametric/?comment=29840#post-id-29840It is not very easy to read the question. Would you mind editing using LaTeX syntax and indenting code blocks?
ps Is this the longest question we have seen aruond ask.sagemath?Thu, 08 Oct 2015 16:46:53 +0200https://ask.sagemath.org/question/29836/plotting-families-depending-on-integer-parameters-of-curvilinear-coordinate-and-isolevel-lines-and-surfaces-resp-for-functional-and-parametric/?comment=29840#post-id-29840Answer by shao-linux for <div class="snippet"><p>To begin with a warning: I am a very experienced mathematician but a complete – 'greenhorn' – beginner in SAGE.
I would like to be able to plot in the same 3D plot FAMILIES OF PARAMETRIC CURVES IN 3D (x(i)=x(t,i),y=y(t,i),z=z(t,i)) plotted via e.g. parametric_plot3D DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i in range(I+1) where the coordinate functions x,y,z are defined as functions of t by me and are not necessarily predefined SAGE functions, and where I can vary the non-negative integer I without varying the code.
I would like to do the same for FAMILIES OF FUNCTIONAL SURFACES (z=f(x,y,i), DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i) using e.g. ParametricSurface, as well as TO DO THE SAME for FAMILIES OF PARAMETRIC SURFACES ( (fx(u,v,i),fy(u,v,i),fz(u,v,i)) ) via using e.g. parametric_plot3D DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i in range(I+1.
I would also like to be able to do the same for FAMILIES OF IMPLICITLY DEFINED SURFACES IN 3D DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i, using e.g. implicit_plot3d ( (f(x,y,z)-C(i)==0, I in range (I+1)), C being a 1-dimensional array (in general algorithmic language) with entries – real numbers in the range of the values of the real-valued f), with the possibility of custom definition of f, I and C.
Examining the SAGE tutorials and reference manuals, I have so far been able to find a model solution of this problem only for planar curves in 2D using plot() and only for SAGE-predefined curves (namely, polynomial curves):
<a href="http://sage.maa.org/home/pub/140/">http://sage.maa.org/home/pub/140/</a> </p>
<p>sage: lotsa_plots = sum([plot(x^n,(x,0,1),color=rainbow(5)[n]) for n in range(5)])
Already in this simple 2D case, if the SAGE-predefined function x^n in the above example be replaced by a custom-defined function f(x,n) , it is not clear to me (a greenhorn!) how to extend the above instance to plotting together the 2D graphs of f(x,n), color=rainbow(N)[n]) for n in range(N), where one should be able to vary N withouth modifying the SAGE code.
I think that providing examples solving the above tasks in the SAGE tutorials/manuals (or developing SAGE in this direction if the tasks are currently SAGE-unsolvable!) is of key importance FOR A GREAT MANY OF THE USERS (OR WANNABE USERS) OF SAGE WHO ARE EXPERIENCED THEORETICIANS BUT ARE NOT EXPERIENCED PROGRAMMERS.
To facilitate the eventual answering of these questions, I herewith propose a simple but comprehensive example. IF YOU PROVIDE COMPLETE ANSWERS CONCERNING THIS EXAMPLE, YOU WILL HAVE ANSWERED ALL OF THE ABOVE QUESTIONS TOGETHER. Moreover, your answer would certainly merit to be included among the examples in the next version(s) of the SAGE tutorial[(s) and/or reference manual(s). <br/>
Consider the 3D scalar field (argument is a 3D vector ...</br/><span class="expander"> <a>(more)</a></span></p></div> https://ask.sagemath.org/question/29836/plotting-families-depending-on-integer-parameters-of-curvilinear-coordinate-and-isolevel-lines-and-surfaces-resp-for-functional-and-parametric/?answer=29857#post-id-29857I believe that the following (tested) code provides a simple, yet complete answer to my question:
First, for functional surfaces (z=f(x,y)), the following code provides an alternative to the solution invoking the class ParametrizedSurface3D: here we only use parametric_plot3d:
M=5
funcsurfplot=[0 for i in range(M)]
x, y = var ('x, y', domain='real')
n=var('n', domain='integer')
funcsurfplot=[parametric_plot3d((x, y, exp(-(x^2+y^2)/(n+1))), \ (x, -2-n, 2+n), (y, -2-n, 2+n), \ color=rainbow(M)[n], opacity=0.3, mesh=True) for n in range(M)]
P=sum(funcsurfplot[i] for i in range(M))
P.show(viewer='jmol')
Note that in this case we have full control over the domains of each of the functions in the family of surfaces, and that these domains can also depend on the integer parameter of the family. The line "funcsurfplot=[0 for i in range(M)]" might be considered redundant, but I prefer it for creation of array-like list in Python with custom size, because, unlike the use of 'append', this approach allows the easy construction of multidimensional arrays (two dimensional arrays would be needed for visualizing the families of coordinate surfaces in the example I gave in the formulation of the question) -- see, e.g.,
http://www.i-programmer.info/programming/python/3942-arrays-in-python.html
Now all the other cases of the question can be resolved in the same simple uniform way, as follows:
Second, meshes of 3D curves (curvilinear coordinates in 3D and on surfaces):
M=5
curve3dplot=[0 for i in range(M)] # creation of array of size M+1 via initialization
t=var ('t', domain='real')
n=var('n', domain='integer')
curve3dplot=[parametric_plot3d((exp(-(n+t)^2), cos(n*t*pi), 1/(1+n*t^2)), (t, -1, 1), \ color=rainbow(M)[n], thickness=4) for n in range(M)]
P=sum(curve3dplot[i] for i in range(M))
P.show(viewer='jmol')
Third, families of parametric surfaces (the surfaces chosen here are Klein bottles of the default type in SAGE - see
http://doc.sagemath.org/html/en/reference/riemannian_geometry/sage/geometry/riemannian_manifolds/surface3d_generators.html
and, in order to introduce dependence on n also in the parametric domains, I have slightly 'unzipped' them):
M=5
parasurf3dplot=[0 for i in range(M)]
u, v = var ('u, v', domain='real')
n=var('n', domain='integer')
def fx(u,v,n): return ((n+1)/M+cos(u/2)*cos(v)-sin(u/2)*sin(2*v))*cos(u)
def fy(u,v,n): return ((n+1)/M+cos(u/2)*cos(v)-sin(u/2)*sin(2*v))*sin(u)
def fz(u,v,n): return sin(u/2)*cos(v)+cos(u/2)*sin(2*v)
def rangeu(n): return (u, -pi+(n/M^3)*pi,pi-(n/M^3)*pi)
def rangev(n): return (v, -pi+(n/M^3)*pi,pi-(n/M^3)*pi)
parasurf3dplot=[parametric_plot3d((fx(u,v,n), fy(u,v,n), fz(u,v,n)), rangeu(n), rangev(n), \ color=rainbow(M)[n], opacity=0.1, mesh=True) for n in range(M)]
P=sum(parasurf3dplot[i] for i in range(M))
P.show(viewer='jmol')
Fourth, families of isosurfaces:
M=5
isosurfplot=[0 for i in range(M)]
x, y, z = var ('x, y, z', domain='real')
n=var('n', domain='integer')
isosurfplot=[implicit_plot3d(x^2+y^2+z^2-(n+1)^2, \ (x,-2-2*n/(M-1),2+2*n/(M-1)),(y,-2-2*n/(M-1),2+2*n/(M-1)),(z,-2-2*n/(M-1),2+2*n/(M-1)), \ color=rainbow(M)[n], opacity=0.3) for n in range(M)]
P=sum(isosurfplot[i] for i in range(M))
P.show(viewer='jmol')
Enjoy the results and feel very welcome to improve and optimize this code. I suggest that in the next version of the SAGE tutorial and/or reference manual there appears a subtopic dedicated to this, as a 3D-upgrade of the topic about contour plots. If, for this to happen, assistance is required from me, I will provide such assistance.
shao-linux :)
----------
My previous text:
Thank you for your comment – I apologize for the long and untidy presentation. Here are the latex formulae which got messed up in my text:
$$F(x,y,z)=exp(-x^2)((cos(y\pi))^2)(1/(1+z^2)), \quad -1\leq x,y,z\leq 1.$$
In the example, x_i, y_j, z_k and c_l are strictly increasing knot-vectors between 0 and 1.
Here is a piece of SAGE code for a simple case which is tested and produces the necessary graphical output via jmol:
sage: x,y=var('x,y');
sage: def f0(x,y,n): return x, y, exp(-(x**2 + y**2));
sage: def f1(x,y): return x, y, exp(-(x**2 + y**2)/2);
sage: def f0(x,y): return x, y, exp(-(x**2 + y**2)/1);
sage: def f2(x,y): return x, y, exp(-(x**2 + y**2)/3);
sage: def f3(x,y): return x, y, exp(-(x**2 + y**2)/4);
sage: def f4(x,y): return x, y, exp(-(x**2 + y**2)/5);
sage: P0 = ParametricSurface(f0, (srange(-2, 2, 0.1), srange(-2, 2, 0.1)), color=rainbow(5)[0], opacity=0.5);
sage: P1 = ParametricSurface(f1, (srange(-2, 2, 0.1), srange(-2, 2, 0.1)), color=rainbow(5)[1], opacity=0.5);
sage: P2 = ParametricSurface(f2, (srange(-2, 2, 0.1), srange(-2, 2, 0.1)), color=rainbow(5)[2], opacity=0.5);
sage: P3 = ParametricSurface(f3, (srange(-2, 2, 0.1), srange(-2, 2, 0.1)), color=rainbow(5)[3], opacity=0.5);
sage: P4 = ParametricSurface(f4, (srange(-2, 2, 0.1), srange(-2, 2, 0.1)), color=rainbow(5)[4], opacity=0.5);
sage: P=P0+P1+P2+P3+P4;
sage: P.show(viewer='jmol')
Launched jmol viewer for Graphics3d Object
This works, but is very inconvenient in this form, because the increase of the number of curves from 5 to, say, N where N can be large, e.g., N=100, would require the definition of 95 more functions f5,...,f99 and 95 more plots P5,...P99, after which we would need to write explicitly
$$P=P1+\dots+P99$$
Evidently, one should prefer something of the type (this new piece of 'code' is just to clarify my request: clearly it is not going to work in SAGE 'as is'):
N=100;
x,y,n=var('x,y,n');
def f(x,y,n): return x,y,n, exp(-(x^2 + y^2)/(n+1));
for n in range(N): def Pplot(n): return n, ParametricSurface(f, (srange(-2, 2, 0.1), srange(-2, 2, 0.1)), color=rainbow(N)[n], opacity=0.5);
P=sum(Pplot(n), n in range(N));
P.show(viewer='jmol')
One might argue that $exp(-(x^2 + y^2)/(n+1))$ is also SAGE-predefined function, so let us assume that the function f(x,y,n) is NOT a SAGE-predefined function (e.g., defined by an elliptic integral which is being computed numerically for x and y).
Here ParametricSurface is involved; for the cases described in the example, this idea must work also with parametric_plot3d (for curves and for surfaces in 3D) and with implicit_plot3d, preferably both variants A and B as described in my text.
See also the discussion at http://sourceforge.net/p/jmol/mailman/message/23809652/
If you provide answers for the proposed example, the problem about meshes and the use of jmol, as discussed in the link given above, would be solved in a very satisfactory way.Fri, 09 Oct 2015 00:00:03 +0200https://ask.sagemath.org/question/29836/plotting-families-depending-on-integer-parameters-of-curvilinear-coordinate-and-isolevel-lines-and-surfaces-resp-for-functional-and-parametric/?answer=29857#post-id-29857Answer by fidbc for <div class="snippet"><p>To begin with a warning: I am a very experienced mathematician but a complete – 'greenhorn' – beginner in SAGE.
I would like to be able to plot in the same 3D plot FAMILIES OF PARAMETRIC CURVES IN 3D (x(i)=x(t,i),y=y(t,i),z=z(t,i)) plotted via e.g. parametric_plot3D DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i in range(I+1) where the coordinate functions x,y,z are defined as functions of t by me and are not necessarily predefined SAGE functions, and where I can vary the non-negative integer I without varying the code.
I would like to do the same for FAMILIES OF FUNCTIONAL SURFACES (z=f(x,y,i), DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i) using e.g. ParametricSurface, as well as TO DO THE SAME for FAMILIES OF PARAMETRIC SURFACES ( (fx(u,v,i),fy(u,v,i),fz(u,v,i)) ) via using e.g. parametric_plot3D DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i in range(I+1.
I would also like to be able to do the same for FAMILIES OF IMPLICITLY DEFINED SURFACES IN 3D DEPENDING ON A NON-NEGATIVE INTEGER PARAMETER i, using e.g. implicit_plot3d ( (f(x,y,z)-C(i)==0, I in range (I+1)), C being a 1-dimensional array (in general algorithmic language) with entries – real numbers in the range of the values of the real-valued f), with the possibility of custom definition of f, I and C.
Examining the SAGE tutorials and reference manuals, I have so far been able to find a model solution of this problem only for planar curves in 2D using plot() and only for SAGE-predefined curves (namely, polynomial curves):
<a href="http://sage.maa.org/home/pub/140/">http://sage.maa.org/home/pub/140/</a> </p>
<p>sage: lotsa_plots = sum([plot(x^n,(x,0,1),color=rainbow(5)[n]) for n in range(5)])
Already in this simple 2D case, if the SAGE-predefined function x^n in the above example be replaced by a custom-defined function f(x,n) , it is not clear to me (a greenhorn!) how to extend the above instance to plotting together the 2D graphs of f(x,n), color=rainbow(N)[n]) for n in range(N), where one should be able to vary N withouth modifying the SAGE code.
I think that providing examples solving the above tasks in the SAGE tutorials/manuals (or developing SAGE in this direction if the tasks are currently SAGE-unsolvable!) is of key importance FOR A GREAT MANY OF THE USERS (OR WANNABE USERS) OF SAGE WHO ARE EXPERIENCED THEORETICIANS BUT ARE NOT EXPERIENCED PROGRAMMERS.
To facilitate the eventual answering of these questions, I herewith propose a simple but comprehensive example. IF YOU PROVIDE COMPLETE ANSWERS CONCERNING THIS EXAMPLE, YOU WILL HAVE ANSWERED ALL OF THE ABOVE QUESTIONS TOGETHER. Moreover, your answer would certainly merit to be included among the examples in the next version(s) of the SAGE tutorial[(s) and/or reference manual(s). <br/>
Consider the 3D scalar field (argument is a 3D vector ...</br/><span class="expander"> <a>(more)</a></span></p></div> https://ask.sagemath.org/question/29836/plotting-families-depending-on-integer-parameters-of-curvilinear-coordinate-and-isolevel-lines-and-surfaces-resp-for-functional-and-parametric/?answer=29877#post-id-29877 One suggestion would be to use
M=10
surfaces = [ParametrizedSurface3D( (x,y,exp(-(x^2+y^2)/n)), (x,y)) for n in range(1,M+1)]
plot = sum([ s.plot(color=rainbow(M)[i],opacity=0.5) for i,s in enumerate(surfaces)])
plot.show()
Just learned that `ParametrizedSurface3D` is a surface object, not a plot. So we first create the surfaces and then we render the plot, which will be the sum of all plots of the previously defined surfaces. I guess you can replace `exp(-(x^2+y^2)/n` by any other function, but that is just a guess.Fri, 09 Oct 2015 17:52:38 +0200https://ask.sagemath.org/question/29836/plotting-families-depending-on-integer-parameters-of-curvilinear-coordinate-and-isolevel-lines-and-surfaces-resp-for-functional-and-parametric/?answer=29877#post-id-29877Comment by shao-linux for <p>One suggestion would be to use</p>
<pre><code>M=10
surfaces = [ParametrizedSurface3D( (x,y,exp(-(x^2+y^2)/n)), (x,y)) for n in range(1,M+1)]
plot = sum([ s.plot(color=rainbow(M)[i],opacity=0.5) for i,s in enumerate(surfaces)])
plot.show()
</code></pre>
<p>Just learned that <code>ParametrizedSurface3D</code> is a surface object, not a plot. So we first create the surfaces and then we render the plot, which will be the sum of all plots of the previously defined surfaces. I guess you can replace <code>exp(-(x^2+y^2)/n</code> by any other function, but that is just a guess.</p>
https://ask.sagemath.org/question/29836/plotting-families-depending-on-integer-parameters-of-curvilinear-coordinate-and-isolevel-lines-and-surfaces-resp-for-functional-and-parametric/?comment=29909#post-id-29909Thank you for your kind response and the proposed solution, fidbc. I tested it and it works properly and is a good starting point. However, to solve the problem of designing and plotting arbitrary parametric meshes (which is implemented, say, in Mathematica) we need more. First, we need to have control over the range of parameters; second, it is somehow unnatural to use for plotting a class (ParametrizedSurface3D) relevant to the intrinsic geometry of the surface rather than the class(es) designed for its plotting; third, some of the visualization classes mentioned in my question do not have an attribute 'plot' but only 'show'.Sun, 11 Oct 2015 03:59:25 +0200https://ask.sagemath.org/question/29836/plotting-families-depending-on-integer-parameters-of-curvilinear-coordinate-and-isolevel-lines-and-surfaces-resp-for-functional-and-parametric/?comment=29909#post-id-29909Comment by shao-linux for <p>One suggestion would be to use</p>
<pre><code>M=10
surfaces = [ParametrizedSurface3D( (x,y,exp(-(x^2+y^2)/n)), (x,y)) for n in range(1,M+1)]
plot = sum([ s.plot(color=rainbow(M)[i],opacity=0.5) for i,s in enumerate(surfaces)])
plot.show()
</code></pre>
<p>Just learned that <code>ParametrizedSurface3D</code> is a surface object, not a plot. So we first create the surfaces and then we render the plot, which will be the sum of all plots of the previously defined surfaces. I guess you can replace <code>exp(-(x^2+y^2)/n</code> by any other function, but that is just a guess.</p>
https://ask.sagemath.org/question/29836/plotting-families-depending-on-integer-parameters-of-curvilinear-coordinate-and-isolevel-lines-and-surfaces-resp-for-functional-and-parametric/?comment=29910#post-id-29910In continuation of my comment, what we need is a simple uniform way of using the two visualization classes: 1. parametric_plot3d for meshes of lines (curvilinear coordinates (fx(t),fy(t),fz(t))), for families of functional surfaces (x,y,f(x,y)) and for families of parametric surfaces (fx(u,v),fy(u,v),fz(u,v)), and 2. implicit_plot3d for families of isosurfaces ( F(x,y,z)==0). After reading your reply and proposed solution, I dug a bit into Python's lists' use as arrays, and found such a simple uniform general answer about the design of arbitrary meshes using the already available tools in SAGE. I will post the respective tested code in updating my 'answer' given below, right after this comment.Sun, 11 Oct 2015 04:19:07 +0200https://ask.sagemath.org/question/29836/plotting-families-depending-on-integer-parameters-of-curvilinear-coordinate-and-isolevel-lines-and-surfaces-resp-for-functional-and-parametric/?comment=29910#post-id-29910