emacs-orgmode
[Top][All Lists]

## Re: [O] Table formula references

 From: Michael Brand Subject: Re: [O] Table formula references Date: Sun, 2 Apr 2017 19:11:15 +0200

```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

> 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>, @address@hidden,

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)) '(@address@hidden) '(@address@hidden))); N %.3f

Michael

```

reply via email to