There have been several questions about solving equations where it seems 
that we haven't featured nsolve enough: nsolve is a great way to get a 
numerical solution to an equation. You can use sympy to do the derivations 
of some equation that you want to solve and then use nsolve to process it 
for given parameters.

On Stock Overflow, a question asked about how to find the distance from a 
point to a function, f.

>>> f=1/(1+exp(-x))
>>> perp_slope = -1/f.diff(x)
>>> line_from_ab = b + perp_slope*(x - a) # or solve(Line((a,b), 
slope=perp_slope).equation(x, y), y)[0]
>>> xcross = Eq(f, line_from_ab)
>>> dist = Point(a, b).distance(Point(x,y))
>>> reps = {a:a, b:b, x: x, y:y}
>>> reps[a]=1;reps[b]=2
>>> reps[x] = nsolve(xcross.subs(reps),x,1)
>>> reps[y] = f.subs(reps)
>>> dist.subs(reps).n(3)
1.25

Now try from (2,2)

>>> reps[a]=2; reps[x]=x; reps[y]=y
>>> reps[x] = nsolve(xcross.subs(reps),x,2)
>>> reps[y] = f.subs(reps)
>>> dist.subs(reps).n(3)
1.11

So...when you want a numeric answer, don't feel stymied if you can't solve 
the expression symbolically for x.

/c

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/6fda0b7b-ab2f-4f7d-9df7-799496545f13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to