The problem I have is as follows:
I have a recursive function b(k)
b(k) = -(A/k**2)*(b(k-2) - b(k-5))
k<0, b(k)=0
k=0, b(k)=1
k=1, b(k)=0
eg. b(2) = -A/4
b(3) = 0
b(4) = A**2/64
note that as k increases b(k) can itself be a sum of terms in powers of A
rather than a single power of A in the examples above.
Summing all terms and equating to zero gives:
F= sum b(k) = 0 for all k = 0, infinity
When this is expanded I get a polynomial F(A). I want to determine the
coefficients of the polynomial so that I can find the roots of the function
F up to a specified order of A.
I have yet to code this but I was hoping for some ideas on how to do this
reasonably.
I figure I can compute each b(k) and store the numeric value(s) and
associated powers of A. Then collect coefficients for like powers of A.
Finally I have a set of polynomial coefficients in A which I can pass to
scipy.base.roots()
Any suggestions on how I might do this efficiently? I have no doubt I can
get this done with brute force, but I would prefer to explore more elegant
means which I look to the masters for.
tia 7 1204
"chris" <cf*****@hotmail.com> wrote in message
news:xN******************@news-server.bigpond.net.au... I have a recursive function b(k)
b(k) = -(A/k**2)*(b(k-2) - b(k-5))
This is specifically called a recurrence relation/
[snip] When this is expanded I get a polynomial F(A). I want to determine the coefficients of the polynomial so that I can find the roots of the function F up to a specified order of A.
This is a math/numerical analysis problem. If you don't get an answer
here, I'd look for a text of recurrence relations and polynomials, and look
for a math/numerical analysis newsgroup. sci.mathematics?
Note: your subject line is so vague that a specialist who can tell you more
could but only selectively opens threads could easily miss this. It is
only happenstance that I didn't.
Terry J. Reedy
On Wed, 27 Apr 2005 11:34:53 GMT, "chris" <cf*****@hotmail.com> wrote: The problem I have is as follows:
I have a recursive function b(k)
b(k) = -(A/k**2)*(b(k-2) - b(k-5)) k<0, b(k)=0 k=0, b(k)=1 k=1, b(k)=0
eg. b(2) = -A/4 b(3) = 0 b(4) = A**2/64
note that as k increases b(k) can itself be a sum of terms in powers of A rather than a single power of A in the examples above.
Summing all terms and equating to zero gives:
F= sum b(k) = 0 for all k = 0, infinity
When this is expanded I get a polynomial F(A). I want to determine the coefficients of the polynomial so that I can find the roots of the function F up to a specified order of A.
I have yet to code this but I was hoping for some ideas on how to do this reasonably.
I figure I can compute each b(k) and store the numeric value(s) and associated powers of A. Then collect coefficients for like powers of A. Finally I have a set of polynomial coefficients in A which I can pass to scipy.base.roots()
Any suggestions on how I might do this efficiently? I have no doubt I can get this done with brute force, but I would prefer to explore more elegant means which I look to the masters for.
Does this look right?
b(-5) -> 0
b(-4) -> 0
b(-3) -> 0
b(-2) -> 0
b(-1) -> 0
b(0) -> 0
b(1) -> 0
b(2) -> -A/4
b(3) -> 0
b(4) -> A**2/64
b(5) -> A/25
b(6) -> -A**3/2304
b(7) -> -29*A**2/4900
b(8) -> A**4/147456
b(9) -> 563*A**3/2116800
b(10) -> A**2/2500 -A**5/14745600
b(11) -> -5927*A**4/1024531200
b(12) -> -43*A**3/980000 +A**6/2123366400
b(13) -> 824003*A**5/11081329459200
b(14) -> 16397*A**4/10372320000 -A**7/416179814400
b(15) -> A**3/562500 -1260403*A**6/1994639302656000
Regards,
Bengt Richter
Seems You are looking for a generating function of a recurrence
relation. There is a standard text about this topic written by Herbert
S. Wilf downloadable from his homapage: http://www.cis.upenn.edu/~wilf/
Regards,
Kay
Hi Terry
I apprecaite the advice. Briefly I'm familiar with the math (its an
eigenvalue problem in fluid flow) but not so much with python (3 months
on and off), hence my post here. I'm looking for python advice on how
to implement this effectively. I love python and would like to use it
well.
As for vague subject, I've not found a strong correlation between
subject line and number or depth of responses. Perhaps today the
curious looked at it. But at other times, even with a quite specific
subject, no replies come. Such is life.
Hi Bengt
OK, that's right. So I'm curious how you did this. And any comments on
how to collect coefficients of like powers in your result.
Be Well and Happy Always
Chris
You could probably use scipy.base.polynomial, but it's easy enough to
implement a polynomial yourself. Just use a dict-- each key represents
the power and each value the coefficient of the polynomial.
You didn't say exactly how efficient you need this. It takes only a
couple seconds to sum 100 of the b(k)'s using the implementation below.
This gets you roots out to about A=500.
Perhaps there are bugs in the below implementation. Either way, you
can compare your results and its results and if they're not the same,
well then there's a problem.
------------------------------------------
from rational import rational #get from bitconjurer.org/rational.py
def add(a, b, s=1):
c = {}
for k, v in b.items():
if not a.has_key(k):
c[k] = s*v
for k, v in a.items():
vb = b.get(k, 0)
c[k] = a[k] + s*vb
return c
def raise1(a):
b = {}
for k, v in a.items():
b[k+1] = v
return b
def scale(a, s):
b = {}
for k, v in a.items():
b[k] = v*s
return b
def eval(x, p):
s = 0.0
for k, v in p.items():
s = s + float(v.num)/float(v.den)*x**k
return s
b = {-3 : {}, -2 : {}, -1 : {}, 0 : {0:rational(1,1)}, 1 : {}}
N = 100
for k in range(2,N):
b[k] = scale(raise1(add(b[k-5],b[k-2],-1)),rational(1,k**2))
o = [b[0]]
for k in range(1, N):
o.append(add(o[-1], b[k]))
for x in range(0,800):
print x, eval(x, o[-3]), eval(x, o[-2]), eval(x, o[-1])
# o[-1],o[-2], and o[-3] start to split around x = 500
Hi bgs
Many thanks. This generates the correct coefficients. I am studying
your implementation now. I've not used a dictionary of dictionaries
before so there's a bit of a learning curve going on right now. However
I can see that b[k] holds the relevant info (coefficients and powers)
so I can easily modify it to collect terms with like powers. As for
speed, its not a concern. Thanks again.
bwaha Chris This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: linux newbie |
last post by:
Hi all java experts, sorry to ask stupid question again, because i am a
java newbie, i would like to have some suggestions/comparsions of good
java IDE tool with gui feature (that enables me to...
|
by: Jason Daly |
last post by:
I am looking for suggestions on book titles.
I want great books for:
ASP (VbScript)
SQL
PHP
CSS
XML
Suggestions for or against any titles?
|
by: Ron Ruble |
last post by:
I'd like to get suggestions from some of the folks here
regarding tools and processes for a new, small development
team.
I'm starting a new job next week, and part of the fun is
being able to...
|
by: Steve |
last post by:
Hi;
I am looking for suggestions about how to solve a problem using tsql.
I have been asked to create a report concerning 4 tables.
Each of the 4 tables is in its own database.
The 4...
|
by: Mark Reed |
last post by:
I am just starting out learning C#... mainly via self study.
I am looking to get away from the networking/management hole I've found
myself in and expand my resume to include development skills.
...
|
by: Brian Basquille |
last post by:
Hello all.
Have been working on the Air Hockey game on and off for a couple of weeks
now.. but have had plenty of other assignments to keep me busy along with
it.
But i would like some...
|
by: Frank Samuelson |
last post by:
I love Python, and it is one of my 2 favorite
languages. I would suggest that Python steal some
aspects of the S language.
-------------------------------------------------------
1. Currently...
|
by: rnd me |
last post by:
Purpose: Allows you to create "presets" for text form inputs.
"Lightweight and simple to setup, it adds a lot of convenience for ~1kb of code."
Only one function, two parameters:
First...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |