ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 14 Feb 2017 04:47:54 -0600Numerical solution of a system of non linear equationshttp://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/Hi everybody! I would like to know whether there exists a simple way to solve in a numerical way a system of non linear equations (the system cannot be solved analytically).
In particular, the system (in the variables a,b) I'd like to solve is the following:
-2*(a*b/sqrt(-1/2*a^2 + b^2) - 2/(a^2*b^2))*(sqrt(-1/2*a^2 + b^2)*b - 1/(a*b^2)) - 16/(a^5*b^2)=0
4*b^3 + 4*(sqrt(-1/2*a^2 + b^2)*b - 1/(a*b^2))*(b^2/sqrt(-1/2*a^2 + b^2) + sqrt(-1/2*a^2 + b^2) + 2/(a*b^3)) - 8/(a^4*b^3)=0
Thanks in advanced,
FrancescoSun, 11 Dec 2011 22:21:08 -0600http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/Comment by Francesco for <p>Hi everybody! I would like to know whether there exists a simple way to solve in a numerical way a system of non linear equations (the system cannot be solved analytically).
In particular, the system (in the variables a,b) I'd like to solve is the following:</p>
<p>-2<em>(a</em>b/sqrt(-1/2<em>a^2 + b^2) - 2/(a^2</em>b^2))<em>(sqrt(-1/2</em>a^2 + b^2)<em>b - 1/(a</em>b^2)) - 16/(a^5*b^2)=0</p>
<p>4<em>b^3 + 4</em>(sqrt(-1/2<em>a^2 + b^2)</em>b - 1/(a<em>b^2))</em>(b^2/sqrt(-1/2<em>a^2 + b^2) + sqrt(-1/2</em>a^2 + b^2) + 2/(a<em>b^3)) - 8/(a^4</em>b^3)=0</p>
<p>Thanks in advanced,
Francesco</p>
http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/?comment=20720#post-id-20720Yes, I corrected my original post with the equations I need to solve numericallyMon, 12 Dec 2011 01:11:53 -0600http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/?comment=20720#post-id-20720Comment by Volker Braun for <p>Hi everybody! I would like to know whether there exists a simple way to solve in a numerical way a system of non linear equations (the system cannot be solved analytically).
In particular, the system (in the variables a,b) I'd like to solve is the following:</p>
<p>-2<em>(a</em>b/sqrt(-1/2<em>a^2 + b^2) - 2/(a^2</em>b^2))<em>(sqrt(-1/2</em>a^2 + b^2)<em>b - 1/(a</em>b^2)) - 16/(a^5*b^2)=0</p>
<p>4<em>b^3 + 4</em>(sqrt(-1/2<em>a^2 + b^2)</em>b - 1/(a<em>b^2))</em>(b^2/sqrt(-1/2<em>a^2 + b^2) + sqrt(-1/2</em>a^2 + b^2) + 2/(a<em>b^3)) - 8/(a^4</em>b^3)=0</p>
<p>Thanks in advanced,
Francesco</p>
http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/?comment=20721#post-id-20721Can you be a bit more vague, your description contains too many details.
Seriously, what kind of equations? algebraic, differential, polynomial, transcendental, ...Mon, 12 Dec 2011 00:47:35 -0600http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/?comment=20721#post-id-20721Answer by maaaaaaartin for <p>Hi everybody! I would like to know whether there exists a simple way to solve in a numerical way a system of non linear equations (the system cannot be solved analytically).
In particular, the system (in the variables a,b) I'd like to solve is the following:</p>
<p>-2<em>(a</em>b/sqrt(-1/2<em>a^2 + b^2) - 2/(a^2</em>b^2))<em>(sqrt(-1/2</em>a^2 + b^2)<em>b - 1/(a</em>b^2)) - 16/(a^5*b^2)=0</p>
<p>4<em>b^3 + 4</em>(sqrt(-1/2<em>a^2 + b^2)</em>b - 1/(a<em>b^2))</em>(b^2/sqrt(-1/2<em>a^2 + b^2) + sqrt(-1/2</em>a^2 + b^2) + 2/(a<em>b^3)) - 8/(a^4</em>b^3)=0</p>
<p>Thanks in advanced,
Francesco</p>
http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/?answer=36612#post-id-36612You can try minimizing `sqrt(f1(a,b)**2 + f2(a,b)**2)` using `sage.minimize`.Tue, 14 Feb 2017 04:47:54 -0600http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/?answer=36612#post-id-36612Answer by DSM for <p>Hi everybody! I would like to know whether there exists a simple way to solve in a numerical way a system of non linear equations (the system cannot be solved analytically).
In particular, the system (in the variables a,b) I'd like to solve is the following:</p>
<p>-2<em>(a</em>b/sqrt(-1/2<em>a^2 + b^2) - 2/(a^2</em>b^2))<em>(sqrt(-1/2</em>a^2 + b^2)<em>b - 1/(a</em>b^2)) - 16/(a^5*b^2)=0</p>
<p>4<em>b^3 + 4</em>(sqrt(-1/2<em>a^2 + b^2)</em>b - 1/(a<em>b^2))</em>(b^2/sqrt(-1/2<em>a^2 + b^2) + sqrt(-1/2</em>a^2 + b^2) + 2/(a<em>b^3)) - 8/(a^4</em>b^3)=0</p>
<p>Thanks in advanced,
Francesco</p>
http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/?answer=13002#post-id-13002You could use mpmath's multidimensional solver, but unfortunately it's not well-wrapped either. On the bright side you can do it without any Cython:
import mpmath
var("a b")
eq0 = -2*(a*b/sqrt(-1/2*a^2 + b^2) - 2/(a^2*b^2))*(sqrt(-1/2*a^2 + b^2)*b - 1/(a*b^2)) - 16/(a^5*b^2)==0
eq1 = 4*b^3 + 4*(sqrt(-1/2*a^2 + b^2)*b - 1/(a*b^2))*(b^2/sqrt(-1/2*a^2 + b^2) + sqrt(-1/2*a^2 + b^2) + 2/(a*b^3)) - 8/(a^4*b^3)==0
f = [lambda a,b: eq0.lhs().subs(a=RR(a), b=RR(b)),
lambda a,b: eq1.lhs().subs(a=RR(a), b=RR(b))]
found_root = mpmath.findroot(f, (2, 2))
found_root = Matrix(RR, found_root.tolist())
print found_root
fa,fb = found_root.list()
print eq0.subs(a=fa,b=fb)
print eq1.subs(a=fa,b=fb)
which gives:
sage: load "rfind.sage"
[1.49174202118713]
[1.10177415033843]
(-2.67785793539588e-13) == 0
(4.93827201353270e-13) == 0
and so we see it's done a decent job. The above was a very manual wrapping, it wouldn't be that much harder to treat the general case.
Tue, 13 Dec 2011 05:28:53 -0600http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/?answer=13002#post-id-13002Answer by Volker Braun for <p>Hi everybody! I would like to know whether there exists a simple way to solve in a numerical way a system of non linear equations (the system cannot be solved analytically).
In particular, the system (in the variables a,b) I'd like to solve is the following:</p>
<p>-2<em>(a</em>b/sqrt(-1/2<em>a^2 + b^2) - 2/(a^2</em>b^2))<em>(sqrt(-1/2</em>a^2 + b^2)<em>b - 1/(a</em>b^2)) - 16/(a^5*b^2)=0</p>
<p>4<em>b^3 + 4</em>(sqrt(-1/2<em>a^2 + b^2)</em>b - 1/(a<em>b^2))</em>(b^2/sqrt(-1/2<em>a^2 + b^2) + sqrt(-1/2</em>a^2 + b^2) + 2/(a<em>b^3)) - 8/(a^4</em>b^3)=0</p>
<p>Thanks in advanced,
Francesco</p>
http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/?answer=13000#post-id-13000The included GSL library has a multi-dimensional numerical root finder `gsl_multiroot_function()` but it seems that Sage does not wrap that functionality. You could write your own wrapper. Should be easy enough using `sage/gsl/gsl_roots.pxi` as a template.
Alternatively, you can introduce dummy variables for the square roots and clear denominators. This will give you a system of polynomial equations which you can attack using Groebner basis techniques.Tue, 13 Dec 2011 03:50:09 -0600http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/?answer=13000#post-id-13000Answer by DSM for <p>Hi everybody! I would like to know whether there exists a simple way to solve in a numerical way a system of non linear equations (the system cannot be solved analytically).
In particular, the system (in the variables a,b) I'd like to solve is the following:</p>
<p>-2<em>(a</em>b/sqrt(-1/2<em>a^2 + b^2) - 2/(a^2</em>b^2))<em>(sqrt(-1/2</em>a^2 + b^2)<em>b - 1/(a</em>b^2)) - 16/(a^5*b^2)=0</p>
<p>4<em>b^3 + 4</em>(sqrt(-1/2<em>a^2 + b^2)</em>b - 1/(a<em>b^2))</em>(b^2/sqrt(-1/2<em>a^2 + b^2) + sqrt(-1/2</em>a^2 + b^2) + 2/(a<em>b^3)) - 8/(a^4</em>b^3)=0</p>
<p>Thanks in advanced,
Francesco</p>
http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/?answer=13003#post-id-13003You could use mpmath's multidimensional solver, but unfortunately it's not well-wrapped either. On the bright side you can do it without any Cython:
import mpmath
var("a b")
eq0 = -2*(a*b/sqrt(-1/2*a^2 + b^2) - 2/(a^2*b^2))*(sqrt(-1/2*a^2 + b^2)*b - 1/(a*b^2)) - 16/(a^5*b^2)==0
eq1 = 4*b^3 + 4*(sqrt(-1/2*a^2 + b^2)*b - 1/(a*b^2))*(b^2/sqrt(-1/2*a^2 + b^2) + sqrt(-1/2*a^2 + b^2) + 2/(a*b^3)) - 8/(a^4*b^3)==0
f = [lambda a,b: eq0.lhs().subs(a=RR(a), b=RR(b)),
lambda a,b: eq1.lhs().subs(a=RR(a), b=RR(b))]
found_root = mpmath.findroot(f, (2, 2))
found_root = Matrix(RR, found_root.tolist())
print found_root
fa,fb = found_root.list()
print eq0.subs(a=fa,b=fb)
print eq1.subs(a=fa,b=fb)
which gives:
sage: load "rfind.sage"
[1.49174202118713]
[1.10177415033843]
(-2.67785793539588e-13) == 0
(4.93827201353270e-13) == 0
and so we see it's done a decent job. The above was a very manual wrapping, it wouldn't be that much harder to treat the general case.
Tue, 13 Dec 2011 05:30:06 -0600http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/?answer=13003#post-id-13003Answer by Francesco for <p>Hi everybody! I would like to know whether there exists a simple way to solve in a numerical way a system of non linear equations (the system cannot be solved analytically).
In particular, the system (in the variables a,b) I'd like to solve is the following:</p>
<p>-2<em>(a</em>b/sqrt(-1/2<em>a^2 + b^2) - 2/(a^2</em>b^2))<em>(sqrt(-1/2</em>a^2 + b^2)<em>b - 1/(a</em>b^2)) - 16/(a^5*b^2)=0</p>
<p>4<em>b^3 + 4</em>(sqrt(-1/2<em>a^2 + b^2)</em>b - 1/(a<em>b^2))</em>(b^2/sqrt(-1/2<em>a^2 + b^2) + sqrt(-1/2</em>a^2 + b^2) + 2/(a<em>b^3)) - 8/(a^4</em>b^3)=0</p>
<p>Thanks in advanced,
Francesco</p>
http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/?answer=13004#post-id-13004Thank you very much!
Best,
fTue, 13 Dec 2011 06:10:27 -0600http://ask.sagemath.org/question/8546/numerical-solution-of-a-system-of-non-linear-equations/?answer=13004#post-id-13004