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.Sat, 08 Aug 2015 06:57:41 -0500Efficiently computing the distance from a point to a sethttp://ask.sagemath.org/question/28779/efficiently-computing-the-distance-from-a-point-to-a-set/ I'm working on a 3d vector field, where the derivative at each point is determined by a series, and each term of the series requires computing the distance from the point to a torus. Right now I'm only using 2-3 tori, and am discretizing each one, then computing a list of distances and taking the minimum. This is taking a really long time to run, and still isn't giving me the accuracy I need. Is there any way to improve efficiency in something like this?
The tori are defined via parametric equations, changing for each torus, and with moving centers.
Let
c(n) = 2/3*(4**(r+1)-4)
For every non-negative integer n, i,j in the range (0,2*pi), and k in {1/10, 2/10,...,9/10,1}, T_n is given by
x = 4^n*(2 + cos(j)*cos(i)
y = 4^n*(2 + cos(j))*sin(i) - c(n)
z = 4^n*k*sin(j)
if n is even and
x = 4^n*k*sin(j)
y = 4^n*(2 + cos(j))*sin(i) - c(n)
z = 4^n*(2 + cos(j)*cos(i)
if n is odd.
So far, I've been discretizing the tori using these equations, computing a list of Euclidean distances, and taking the minimum.
Here's the full equations for determining the vector field. First, I make a list of points for each torus. For any p = (x,y,z) in R^3, define a sequence of functions, with
h_0(p) = min(1, 1-d(p,T_0))
h_n(p) = min(1, d(p,T_(n-1)), 1-d(p,T_n))
Additionally, define
G_n(p) = (y,-x,0)
if n is even and
G_n(p) = (0,-z,y)
if n is odd.
Finally, for each point p in R^3, the derivative at p is given by
dp = sum(G_n(p - (0,c(n),0))*h_n(p))
over all non-negative integers n. So far I've been restricting myself to the n = 0,1,2 case, but even then, I generally can't get the field to display unless I make the discretization really large, and that doesn't show the detail I need to help me find out where the alpha and omega limit sets are.
I'm not having any problems writing the code that will make these calculations, I'm just wondering if there is a more efficient way, rather than taking a list of points for the torus, and just computing the minimum over and over again.
jford1906Sat, 08 Aug 2015 06:57:41 -0500http://ask.sagemath.org/question/28779/Plot graph by distance from a given vertexhttp://ask.sagemath.org/question/24623/plot-graph-by-distance-from-a-given-vertex/I have some graphs I'd like to be able to plot in such a way that I can set a "top" vertex $v$, and then make all vertices distance 1 from $v$ be maybe 1 cm/in lower down, the ones distance 2 away be twice and far, and so forth. As it happens, each such set of vertices have no edges between them, so this will look just like a Hasse diagram/lattice/whatever and be meaningful.
But I've racked my head and lambda functions and whatnot to get this to work, and every graph plotting option and use of distance seems to go awry. I need help. I bet someone else does a lot more graph visualization than I do and will have an easy answer. (I suppose as a last resort I could use a dictionary for the locations and concoct info for that, but I am hoping it will be something I can do without having to construct the graph first.)kcrismanFri, 24 Oct 2014 09:35:38 -0500http://ask.sagemath.org/question/24623/how to calculate distance between origin and furthest point on graph?http://ask.sagemath.org/question/9567/how-to-calculate-distance-between-origin-and-furthest-point-on-graph/Hello!
I am new on this forum so forgive me if I don't respect all "rules" or if someone answered already this question.
![image description](http://oi45.tinypic.com/ve3i2e.jpg)
If you take a look at the image, I just want to know how to calculate the distance between origin and the furthest dot on the graph.
code:
var('t')
ff = (exp(cos(t)) - 2*cos(4*t) + sin(t/12)^5)
parametric_plot((ff*cos(t),ff*sin(t)), (t,0,2*pi) , fill=True, fillcolor='orange', figsize=[3,3])
mario_rujaMon, 26 Nov 2012 08:55:31 -0600http://ask.sagemath.org/question/9567/How to find the path of the maximal distance between two vertices on a complete digraph?http://ask.sagemath.org/question/9000/how-to-find-the-path-of-the-maximal-distance-between-two-vertices-on-a-complete-digraph/I was wondering how can I find the path of the maximal distance between two vertices on a complete digraph.
Suppose the digraph has 5 vertices:
`sage: g = graphs.CompleteGraph(5).to_directed()`
I have seen a [maximal flow](http://www.sagemath.org/doc/thematic_tutorials/linear_programming.html#flows) example which is nice but it is not the same type of problem. How can I use sage to find the longest path?
MaelstromYamatoFri, 25 May 2012 07:06:58 -0500http://ask.sagemath.org/question/9000/Sage and distance learninghttp://ask.sagemath.org/question/7698/sage-and-distance-learning/I think Sage and computer algebra software in general, could play an important role in math courses for remotely located students. To some extent and with some guidance I think student
exploration with Sage can replace direct interaction with a math tutor. Are there any distance learning course that currently incorporate Sage as part of the "courseware"? How can Sage be integrated with other packages such as Moodle?Bill PageFri, 17 Sep 2010 03:21:37 -0500http://ask.sagemath.org/question/7698/