> f1=x**2+sin(3*y)
> f2=log(x)-cos(y)
>
> result=nsolve([f1,f2],[x,y],[0,])
>
> how to constrain x in range [-10,10] ??

A nice approach to take is to reduce the 2 equations to a single
equation in x and then solve that in the desired range with bisection:

>>> f1
x**2 + sin(3*y)
>>> f2
log(x) - cos(y)
>>> f2.subs(y,solve(f1,y)[0])
log(x) - cos(asin(x**2)/3)

The 'bisect' method can be used (although there are others like
'anderson' that can be used; the documentation is spotty but you can
look at the classes in mpmath.calculus.optimizations.py to learn about
the different solvers).

>>> nsolve(_,(-10,10),solver='bisect')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy\solvers\solvers.py", line 1758, in nsolve
    return findroot(f, x0, **kwargs)
  File "sympy\mpmath\calculus\optimization.py", line 972, in findroot
    % (norm(f(*xl))**2, tol))
ValueError: Could not find root within given tolerance. (3.05872 > 2.1684e-19)
Try another starting point or tweak arguments.

So there is no root found in that range. This might be because the
initial guess was bad (for the solver). For example,

>>> nsolve(x**2-1,(0,2),solver='bisect')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy\solvers\solvers.py", line 1758, in nsolve
    return findroot(f, x0, **kwargs)
  File "sympy\mpmath\calculus\optimization.py", line 972, in findroot
    % (norm(f(*xl))**2, tol))
ValueError: Could not find root within given tolerance. (1 > 2.1684e-19)
Try another starting point or tweak arguments.

In that case, the solver didn't recognize an exact hit in the
bisection. (The other bisecting methods like Ridder and Illinois have
detection of this condition.) So for bisect, tweak an endpoint until
the error is fixed in mpmath.

>>> nsolve(x**2-1,(0,3),solver='bisect')
mpf('1.0')

Back to your problem, however. If you graph the function in the range
of -10 to 10 you will see that there are no solutions in that range,
so no solver will give you a real solution to the equation set in that
range.

/c

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/sympy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to