# Mathematical calculations

**URL:** <https://discourse.nodered.org/t/mathematical-calculations/56169>\
**Category:** General\
**Tags:** function-node\
**Created:** [5 January 2022 19:06 UTC](https://discourse.nodered.org/t/mathematical-calculations/56169 "2022-01-05T19:06:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![haskle](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@haskle](https://discourse.nodered.org/u/haskle)\
**Post date:** [5 January 2022 19:06 UTC](https://discourse.nodered.org/t/mathematical-calculations/56169/1 "2022-01-05T19:06:22Z")

</div>

I have tried to follow the Help section & previous topics, but I am still stuck ...

In order to calculate the current volume of oil in a horizontal cylindrical tank I need to process several mathematical calculations in turn. Rather than try to do everything in one go, I have broken these down in to series of discrete "sums" using `function` nodes. So far so good.

But I can't work out the syntax to put in a `function Node d` manipulating the output of two others, eg, "the result of `function Node b` minus the result of `function Node c` "

How might I phrase this? I am not sure how to identify the previous output of a function node and put it in to another node for further processing.

Many thanks!

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [5 January 2022 19:15 UTC](https://discourse.nodered.org/t/mathematical-calculations/56169/2 "2022-01-05T19:15:05Z")

</div>

Sounds like you may want to look at saving values then pull them back in when you need them. Look at using flow.save , you should find this in node red docs.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [5 January 2022 19:19 UTC](https://discourse.nodered.org/t/mathematical-calculations/56169/3 "2022-01-05T19:19:05Z")

</div>

You may also want to look at [node-red-contrib-tank-volume - npm](https://www.npmjs.com/package/node-red-contrib-tank-volume) as it may help

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [5 January 2022 19:21 UTC](https://discourse.nodered.org/t/mathematical-calculations/56169/4 "2022-01-05T19:21:57Z")

</div>

You can join the outputs of the two function nodes with a join node like this

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/7588251c207446691af166b67be815011bf35710.jpeg)

```auto
[{"id":"c48f46e577eaf844","type":"function","z":"a3e369ffd4e1629e","name":"","func":"msg.payload = 27;\nmsg.topic = \"topic1\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":120,"wires":[["6c4f6e5cbee8072a"]]},{"id":"3a263e81ac6bd039","type":"function","z":"a3e369ffd4e1629e","name":"","func":"msg.payload = 5;\nmsg.topic = \"topic2\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":160,"wires":[["6c4f6e5cbee8072a"]]},{"id":"6c4f6e5cbee8072a","type":"join","z":"a3e369ffd4e1629e","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":490,"y":140,"wires":[["398e5fefd1268494","3c35d0d4665504b7"]]},{"id":"398e5fefd1268494","type":"function","z":"a3e369ffd4e1629e","name":"","func":"msg.payload = msg.payload.topic1 + msg.payload.topic2;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":140,"wires":[["7aad460a950c31d3"]]},{"id":"2469c14de3faaafc","type":"inject","z":"a3e369ffd4e1629e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":120,"wires":[["c48f46e577eaf844"]]},{"id":"3dbb85870f589efb","type":"inject","z":"a3e369ffd4e1629e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":160,"wires":[["3a263e81ac6bd039"]]},{"id":"7aad460a950c31d3","type":"debug","z":"a3e369ffd4e1629e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":140,"wires":[]},{"id":"3c35d0d4665504b7","type":"debug","z":"a3e369ffd4e1629e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":100,"wires":[]}]

```

And the node @dceejay mentioned is introduced [here](https://discourse.nodered.org/t/announce-node-red-contrib-tank-volume-beta/47101)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 January 2022 21:36 UTC](https://discourse.nodered.org/t/mathematical-calculations/56169/5 "2022-01-05T21:36:45Z")

</div>

Put the calculations one after another, not in parallel. Then it is much easier.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [5 January 2022 21:57 UTC](https://discourse.nodered.org/t/mathematical-calculations/56169/6 "2022-01-05T21:57:17Z")

</div>

"Great minds" think alike. I had this all set to post, honest.

```auto
[{"id":"754ed93fca304316","type":"inject","z":"1a062a4d47b6ea5b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":1140,"wires":[["0de4747b872883fb"]]},{"id":"0de4747b872883fb","type":"function","z":"1a062a4d47b6ea5b","name":"","func":"msg.a = 27;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":1140,"wires":[["540bb50f4da2ae71"]]},{"id":"540bb50f4da2ae71","type":"function","z":"1a062a4d47b6ea5b","name":"","func":"msg.b = 5;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":1140,"wires":[["251b9bc5bc098a8b"]]},{"id":"251b9bc5bc098a8b","type":"function","z":"1a062a4d47b6ea5b","name":"","func":"msg.payload = msg.a + msg.b;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1140,"wires":[["57e15183b4acee15"]]},{"id":"57e15183b4acee15","type":"debug","z":"1a062a4d47b6ea5b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":1140,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 March 2022 21:57 UTC](https://discourse.nodered.org/t/mathematical-calculations/56169/7 "2022-03-06T21:57:21Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
