Is there any way to re-write or group the expression in the function below to make it less sensitive to round-off? Does it help any to break the large expression into
smaller pieces? I suppose matlab already uses double precision. Is there any way to increase the precision beyond that?
Rfac=Rfac + (-1)^s *factorial(n-s)/(factorial(s)*factorial((n+abs(m))/2-s)*factorial((n-abs(m))/2-s))*rho^(n-2*s);
"Peter Schreiber" <firstname.lastname@example.org> wrote in message <email@example.com>...
> Is there any way to re-write or group the expression in the function below to make it less sensitive to round-off? Does it help any to break the large expression into
> smaller pieces? I suppose matlab already uses double precision. Is there any way to increase the precision beyond that?
> for s=0:(n-abs(m))/2
> Rfac=Rfac + (-1)^s *factorial(n-s)/(factorial(s)*factorial((n+abs(m))/2-s)*factorial((n-abs(m))/2-s))*rho^(n-2*s);
It is not possible to give a precise answer to your question, Peter, without knowing what values you contemplate for n, m, and rho. However, perhaps the following will be of some assistance to you.
You are computing the sum of a finite number of terms in a polynomial involving powers of rho. (I assume here that n+abs(m) is even, since your expression would not make sense otherwise.) The coefficients of that polynomial are each certain terms that, except for the alternating signs, occur in the trinomial expansion of a power of the sum of three quantities. Specifically in your case if we let a = s, b = (n+abs(m))/2-s, and c = (n-abs(m))/2-s, then ignoring (-1)^s and rho^(n-2*s) you have
This is the number of ways a+b+c objects can be divided up with a of them in one box, b in another box, and c in a third box and it is always an exact integer.
I am guessing that you will also want to compute such integers exactly. Up until these quantities exceed 2^53, you can presumably use the nchoosek function to make this computation accurately according to the formula
(a+b+c)!/(a!*b!*c!) = (a+b+c)/(a!*(b+c)!) * (b+c)!/(b!*c!)
where each of these two factors can come from nchoosek using
nchoosek(a+b+c,a) * nchoosek(b+c,b)
For a given value of a+b+c the maximum value of this occurs when a, b, and c are approximately equal. In your case that would correspond to m = 0 and n being approximately four times the size of s. I would therefore guess that the calculation using this method would first run into accuracy problems with n = 52, m = 0, and s = 13 or thereabouts, and for the very good reason that higher values of the trinomial coefficients would be too large to be precisely represented in matlab's double precision.
As you can well imagine, using this method will allow one to avoid the inaccuracies of computing directly with the factorial function. For example, with the above value for n, m, and s, you would encounter (n-s)! = factorial(39) in your original expression, which is far, far beyond matlab's double precision capabilities for exact integers.
As for carrying out the rest of your desired computation, a lot would depend on the magnitude of rho. With rho substantially greater than one, the early terms with n-2*s powers of rho would tend to be larger than the later terms, but the reverse is true if rho is less than one. In any case I would favor an ordering of addition/subtraction which proceeds from the smaller magnitudes and ends with the larger ones as a means of best reducing accumulating round-off error. You could accomplish that by sorting the term values in accordance with ascending magnitudes and then carry out the addition of those terms in the corresponding ordering indicated by the sort function.
It may be of at least theoretical interest that the above trinomial coefficients occur in what is known as a Pascal Pyramid, and in your summation you are using the trinomial coefficients along a certain line within that pyramid as s varies. In fact these coefficients could actually be computed by simple addition (admittedly quite a lot of additions) within the pyramid using a method analogous to the generation of binomial coefficients using a Pascal Triangle. For more information on this see the Wikipedia website at:
You can think of your watch list as threads that you have bookmarked.
You can add tags, authors, threads, and even search results to your watch list. This way you can easily keep track of topics that you're interested in. To view your watch list, click on the "My Newsreader" link.
To add items to your watch list, click the "add to watch list" link at the bottom of any page.
To add search criteria to your watch list, search for the desired term in the search box. Click on the "Add this search to my watch list" link on the search results page.
You can also add a tag to your watch list by searching for the tag with the directive "tag:tag_name" where tag_name is the name of the tag you would like to watch.
To add an author to your watch list, go to the author's profile page and click on the "Add this author to my watch list" link at the top of the page. You can also add an author to your watch list by going to a thread that the author has posted to and clicking on the "Add this author to my watch list" link. You will be notified whenever the author makes a post.
To add a thread to your watch list, go to the thread page and click the "Add this thread to my watch list" link at the top of the page.
No tags are associated with this thread.
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.
The newsgroups are a worldwide forum that is open to everyone. Newsgroups are used to discuss a huge range of topics, make announcements, and trade files.
Discussions are threaded, or grouped in a way that allows you to read a posted message and all of its replies in chronological order. This makes it easy to follow the thread of the conversation, and to see what’s already been said before you post your own reply or make a new posting.
Newsgroup content is distributed by servers hosted by various organizations on the Internet. Messages are exchanged and managed using open-standard protocols. No single entity “owns” the newsgroups.
There are thousands of newsgroups, each addressing a single topic or area of interest. The MATLAB Central Newsreader posts and displays messages in the comp.soft-sys.matlab newsgroup.
You can use the integrated newsreader at the MATLAB Central website to read and post messages in this newsgroup. MATLAB Central is hosted by MathWorks.
Messages posted through the MATLAB Central Newsreader are seen by everyone using the newsgroups, regardless of how they access the newsgroups. There are several advantages to using MATLAB Central.
Your MATLAB Central account is tied to your MathWorks Account for easy access.
Use the Email Address of Your Choice
The MATLAB Central Newsreader allows you to define an alternative email address as your posting address, avoiding clutter in your primary mailbox and reducing spam.
Most newsgroup spam is filtered out by the MATLAB Central Newsreader.
Messages can be tagged with a relevant label by any signed-in user. Tags can be used as keywords to find particular files of interest, or as a way to categorize your bookmarked postings. You may choose to allow others to view your tags, and you can view or search others’ tags as well as those of the community at large. Tagging provides a way to see both the big trends and the smaller, more obscure ideas and applications.
Setting up watch lists allows you to be notified of updates made to postings selected by author, thread, or any search variable. Your watch list notifications can be sent by email (daily digest or immediate), displayed in My Newsreader, or sent via RSS feed.
You can also select a location from the following list: