# How do I define a function from previous output?

**URL:** <https://community.wolfram.com/t/how-do-i-define-a-function-from-previous-output/17925>\
**Category:** Questions\
**Created:** [April 4, 2021, 4:17am UTC](https://community.wolfram.com/t/how-do-i-define-a-function-from-previous-output/17925 "2021-04-04T04:17:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![timtaves](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/timtaves/32/29098_2.png) [@timtaves](https://community.wolfram.com/u/timtaves)\
**Post date:** [April 4, 2021, 4:17am UTC](https://community.wolfram.com/t/how-do-i-define-a-function-from-previous-output/17925/1 "2021-04-04T04:17:46Z")

</div>

I would like to define a function from the output of a series calculation without having to copy and paste. My code is below. The first four lines work fine. It’s the final line which doesn’t work. I have to copy the output of the fourth line and paste it on the right side of the final line (where the % currently is located) to make it work but this is very cumbersome.

```
Series[1/Sqrt[(x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2] - 
1/Sqrt[(x2 - x1)^2 + (y2 - y1 + b1)^2 + (z2 - z1)^2], {x1, 0, 
1}, {x2, 0, 1}, {y1, b1, 1}, {y2, 0, 1}, {z1, 0, 1}, {z2, 0, 1}]

Simplify[%, Assumptions -> b1 > 0]

Normal[%]

InputForm[%]

h[x1_, y1_, z1_, x2_, y2_, z2_] :=%

```

---

<div class="post-metadata">

**Author:** ![dontdont9](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@dontdont9](https://community.wolfram.com/u/dontdont9)\
**Post date:** [April 4, 2021, 7:22am UTC](https://community.wolfram.com/t/how-do-i-define-a-function-from-previous-output/17925/2 "2021-04-04T07:22:48Z")

</div>

Try

```
Series[...]
Simplify[...]
f=Normal[%]
h[x1_,y1_,z1_,x2_,y2_,z2_]:=Evaluate[f]

```

and then carefully thoroughly test this with appropriate parameters to verify that it worked

```
h[1,2,3,4,5,6]

```

---

<div class="post-metadata">

**Author:** ![neils](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/neils/32/20595_2.png) [@neils](https://community.wolfram.com/u/neils)\
**Post date:** [April 4, 2021, 9:20am UTC](https://community.wolfram.com/t/how-do-i-define-a-function-from-previous-output/17925/3 "2021-04-04T09:20:52Z")

</div>

Or just use set (=) instead of SetDelayed (:=)

```
h[x1_,y1_,z1_,x2_,y2_,z2_] = f

```

Regards

---

<div class="post-metadata">

**Author:** ![timtaves](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/timtaves/32/29098_2.png) [@timtaves](https://community.wolfram.com/u/timtaves)\
**Post date:** [April 4, 2021, 4:03pm UTC](https://community.wolfram.com/t/how-do-i-define-a-function-from-previous-output/17925/4 "2021-04-04T16:03:54Z")

</div>

This worked, thank you for your help.

---

<div class="post-metadata">

**Author:** ![timtaves](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/timtaves/32/29098_2.png) [@timtaves](https://community.wolfram.com/u/timtaves)\
**Post date:** [April 4, 2021, 4:07pm UTC](https://community.wolfram.com/t/how-do-i-define-a-function-from-previous-output/17925/5 "2021-04-04T16:07:05Z")

</div>

This worked, thank you very much. The difference between your method and Bill’s is that yours shows the output by default, Bill’s doesn’t. I think I need to learn the details about the difference between := and = . Thanks for pointing me in an interesting direction.
