Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.5K Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Use the output of the Normal function as input to a function def?

Posted 6 years ago
POSTED BY: Karl Petersen
3 Replies

Yes, pand should be xpand.

POSTED BY: Daniel Lichtblau

Daniel-- Thank you for looking at this. First, with regard to the "pattern variable", in my Mathematica notebook I did type pand[r_]::= but on one screen I saw it seemed that it did not come across that way with copy and paste.

Second, when on line 238 I define pand1[r_] by copying line 235 (the text explicit literal output of Normal applied to xpand[k,r,5] with k=2) I get a desired actual function of r which I can evaluate on line 240 at r=.2 and get the numerical result.

However, when on line 234 I try to define the function pand[r_] by setting it to the alleged normal expression xpandN5[k,r] with k=2, I do not get a function of r that can be evaluated at r=.2 (line 236). Mathematica still thinks there's a series involved, even though Normal has been applied to the series.By rights pand[r] should no longer be a series, but a function of r.

Third, in your next to last line should xpand be pand? Otherwise how else can pand[.2] be defined? And wouldn't xpand as a function of one variable conflict with its definition above as a function of three variables?

Finally, I'm not yet up to using Module, but maybe that's what's needed to get Normal to work the way I expect? In that case U'll try harder. Thanks again, --Karl

POSTED BY: Karl Petersen

If you trace the computation you will find that there is an attempt to pass .2 as a variable to Series. This fails, so no SeriesData is created, hence Normal has no effect.

Also be aware that some of the definitions are not using pattern variables. I'm guessing this was not by intent. So something along the lines of the code below might be what's wanted.

xpand[k_, r_, n_] := Series[(1 + r)^(1/k), {r, 0, n}]
xpandN5[k_, r_] := 
 Module[{k2, r2}, Normal[xpand[k2, r2, 5]] /. {k2 -> k, r2 -> r}]

xpand[r_] := xpandN5[2, r]
pand[.2]

(* Out[124]= 1.09544625 *)
POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard