From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Brand Subject: Re: Table formula references Date: Sun, 2 Apr 2017 19:11:15 +0200 Message-ID: References: <8760irgnwj.fsf@uibk.ac.at> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45177) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuj27-0005NO-FJ for emacs-orgmode@gnu.org; Sun, 02 Apr 2017 13:11:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cuj26-0000OC-H7 for emacs-orgmode@gnu.org; Sun, 02 Apr 2017 13:11:19 -0400 Received: from mail-qk0-x234.google.com ([2607:f8b0:400d:c09::234]:36838) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cuj26-0000KB-Cn for emacs-orgmode@gnu.org; Sun, 02 Apr 2017 13:11:18 -0400 Received: by mail-qk0-x234.google.com with SMTP id p22so98707160qka.3 for ; Sun, 02 Apr 2017 10:11:16 -0700 (PDT) In-Reply-To: <8760irgnwj.fsf@uibk.ac.at> 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: Manuel Schneckenreither Cc: Org Mode Hi Manuel Not sure if I understand your formulas right, so check my solutions with the formula debugger. On Thu, Mar 30, 2017 at 10:38 AM, Manuel Schneckenreither wrote: > So @5$3 should be 0.9^0*127 + 0.9^1*118 + 0.9^2*121 + 0.9^3*115. Emacs Calc has map with anonymous function and one or more vectors for the above: vsum(map(<0.9^#1 * #2>, [3, 2, 1, 0], [115, 121, 118, 127])) which equals vsum(map(<0.9^(4 - #1) * #2>, [1, 2, 3, 4], [115, 121, 118, 127])) The rest is Org spreadsheet. See the spreadsheet section in the Org user manual to understand this solution: | t | y_t | y_{t+1} | |---+-----+---------| | 1 | 115 | 115.000 | | 2 | 121 | 224.500 | | 3 | 118 | 320.050 | | 4 | 127 | 415.045 | #+TBLFM: $3 = vsum(map(<0.9^($1 - #1) * #2>, @I$1..@0$1, @I$2..@0$2)); f-3 The same with Emacs Lisp: | t | y_t | y_{t+1} | |---+-----+---------| | 1 | 115 | 115.000 | | 2 | 121 | 224.500 | | 3 | 118 | 320.050 | | 4 | 127 | 415.045 | #+TBLFM: $3 = '(apply #'+ (cl-mapcar (lambda (tau y-tau) (* (expt 0.9 (- $1 tau)) y-tau)) '(@I$1..@0$1) '(@I$2..@0$2))); N %.3f Michael