Message Boards Message Boards

1
|
2382 Views
|
4 Replies
|
4 Total Likes
View groups...
Share
Share this post:

How do I define a function from previous output?

Posted 3 years ago

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_] :=%
POSTED BY: Tim Taves
4 Replies

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

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

Regards

POSTED BY: Neil Singer
Posted 3 years ago

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.

POSTED BY: Tim Taves
Posted 3 years ago

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]
POSTED BY: Bill Nelson
Posted 3 years ago

This worked, thank you for your help.

POSTED BY: Tim Taves
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract