No such thing as a small change PerlMonks

Power series computations

by pm5 (Acolyte)
 on Feb 14, 2006 at 03:14 UTC Need Help??

pm5 has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I want to do some ordinary algebraic operations (addition and multiplication) on power series over real or complex numbers. There is no real world purpose except to give myself several examples to play with. In fact, I'll probably just need exp(x) and some trigonometric functions to begin with. A quick CPAN search didn't shed a light, though. Is there any modules that might be helpful?

Replies are listed 'Best First'.
Re: Power series computations
by McDarren (Abbot) on Feb 14, 2006 at 03:22 UTC
Maybe you aren't using appropriate search terms. I tried "math", "algebraic" and "trigonometric" and got dozens of hits. For example:

Cheers,
Darren :)

Re: Power series computations
by rhesa (Vicar) on Feb 14, 2006 at 03:26 UTC
You might want to check out PARI and the wonderful Math::Pari perl wrapper, which lives on CPAN and optionally installs PARI for you.

Here's a quick example run in the gp calculator:

? taylor(exp(y),y) %366 = 1 + y + 1/2*y^2 + 1/6*y^3 + 1/24*y^4 + 1/120*y^5 + 1/720*y^6 + +1/5040*y^7 + 1/40320*y^8 + 1/362880*y^9 + 1/3628800*y^10 + 1/39916800 +*y^11 + 1/479001600*y^12 + 1/6227020800*y^13 + 1/87178291200*y^14 + 1 +/1307674368000*y^15 + O(y^16) ? taylor(sin(y),y) %374 = y - 1/6*y^3 + 1/120*y^5 - 1/5040*y^7 + 1/362880*y^9 - 1/3991680 +0*y^11 + 1/6227020800*y^13 - 1/1307674368000*y^15 + O(y^16) ? taylor(exp(y),y)+taylor(sin(y),y) %375 = 1 + 2*y + 1/2*y^2 + 1/24*y^4 + 1/60*y^5 + 1/720*y^6 + 1/40320*y +^8 + 1/181440*y^9 + 1/3628800*y^10 + 1/479001600*y^12 + 1/3113510400* +y^13 + 1/87178291200*y^14 + O(y^16)
Re: Power series computations
by spiritway (Vicar) on Feb 14, 2006 at 03:32 UTC

You've got atan2, cos, exp, log, sin, and sqrt, all in the core distribution. To perform exponentiation, use x ** y. If you don't want to roll your own complex numbers, you can check out Math::Complex. For the missing trig functions, you can easily make functions (e.g., tan(x)=sin(x)/cos(x), etc.) to do it.

For more complete modules, you might want to tryMath::Taylor or Math::Calculus::TaylorSeries.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://530005]
Approved by McDarren
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-07-23 12:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?
 • erzuuli ‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.