From mboxrd@z Thu Jan 1 00:00:00 1970 From: Miguel Ruiz Subject: Re: Two numerical solutions from fsolve inside calc source block Date: Sat, 02 Jul 2016 11:55:04 +0200 Message-ID: <353700413f4d54742a4ebd748fcba1d2@openmailbox.org> References: <339521829cdbff8e73ad393bd49d7b85@openmailbox.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34243) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJHdp-0008WH-CM for emacs-orgmode@gnu.org; Sat, 02 Jul 2016 05:55:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bJHdj-0005xL-Ft for emacs-orgmode@gnu.org; Sat, 02 Jul 2016 05:55:12 -0400 Received: from mail2.openmailbox.org ([62.4.1.33]:43767) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJHdj-0005vk-6D for emacs-orgmode@gnu.org; Sat, 02 Jul 2016 05:55:07 -0400 Received: from www.openmailbox.org (unknown [10.91.130.51]) by mail2.openmailbox.org (Postfix) with ESMTP id 7D7ED106B29 for ; Sat, 2 Jul 2016 11:55:04 +0200 (CEST) In-Reply-To: <339521829cdbff8e73ad393bd49d7b85@openmailbox.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Emacs Orgmode Not optimal solution: #+begin_src calc :results code fsolve([8.66e10 =3D r * v, -7.51e6 =3D 0.5*v^2 - 6.67e-11*6e24/r],[r,v]) #+end_src yields #+RESULTS: #+BEGIN_SRC calc [r =3D 86600000000. / (4621.24711316 - 2517.12631405 s2), v =3D=20 4621.24711316 - 2517.12631405 s2] #+END_SRC Manually add :var clause in the results block as follows #+RESULTS: #+BEGIN_SRC calc :var var-s2=3D1 [r =3D 86600000000. / (4621.24711316 - 2517.12631405 s2), v =3D=20 4621.24711316 - 2517.12631405 s2] #+END_SRC And finally the modified results block is evaluated #+RESULTS: : [r =3D 41157332.8093, v =3D 2104.12079911] ; var-s2=3D1 and #+RESULTS: : [r =3D 12131615.2598, v =3D 7138.37342721] ; var-s2=3D-1 Any improvement will be appreciated. Miguel. El 2016-06-26 15:53, Miguel Ruiz escribi=C3=B3: > Hi, >=20 > I have this block which is intended to get the two numerical solutions > of the equations system: >=20 > #+begin_src calc > fsolve([8.66e10 =3D r * v, -7.51e6 =3D 0.5*v^2 - 6.67e-11*6e24/r],[r,v]= ) > #+end_src >=20 > This way I get the generic form of a multiple solution, and citing the > manual "It will invent variables n1, n2, =E2=80=A6, which represent > independent arbitrary integers, and s1, s2, =E2=80=A6, which represent > independent arbitrary signs (either +1 or -1)." >=20 > So I get >=20 > #+RESULTS: > : [r =3D 86600000000. / (4621.24711316 - 2517.12631405 s1), v =3D > 4621.24711316 - 2517.12631405 s1] >=20 > Now, to get the two solutions I have to evaluate manually the result > expression replacing s1 by "*1" and "*-1" >=20 > #+begin_src calc > [r =3D 86600000000. / (4621.24711316 - 2517.12631405 *1), v =3D > 4621.24711316 - 2517.12631405 *1] > #+end_src >=20 > #+RESULTS: > : [r =3D 41157332.8093, v =3D 2104.12079911] >=20 > And >=20 > #+begin_src calc > [r =3D 86600000000. / (4621.24711316 - 2517.12631405 *-1), v =3D > 4621.24711316 - 2517.12631405 *-1] > #+end_src >=20 > #+RESULTS: > : [r =3D 12131615.2598, v =3D 7138.37342721] >=20 > Emacs calc manual states "Note that variables like n1 and s1 are not > given any special interpretation in Calc except by the equation solver > itself. As usual, you can use the s l (calc-let) command to obtain > solutions for various actual values of these variables.", but I cannot > figure out a way to call (calc-let) or its algebraic equivalent inside > a calc source block. >=20 > I can accept a only-elisp workaround if it is more convenient. >=20 > Any hint to do everything commented without user interaction? >=20 > Regards.