suppose I have a positive real number T, and I a have a vector of parameters "a" with N elements, and a function f(k,t) on t defined recursively in k, for k<N as follows
(the following is NOT matlab code, it is just pseudo code to illustrate what I need to do, since i am not sure what Matlab data structure to use for the function)
f(0,t) = 1 a constant for all t
f(1,t) = @(t) integral( @(s) exp(-a(1)*s),t,T);
f(2,t) = @(t) integral( @(s) f(1,s)*exp(-a(2)*s),t,T);
f(k,t) =@(t) integral( @(s) f(k-1,s)*exp(-a(k-1)*s),t,T);
So if I knew what value "k" is beforehand I can just probably write everything down from 0 to k, maybe the f's are functions stored as a cell array in 'k'.
But I want to generalize this so that I compute f(k,t) for various "k" without having to write everything down. Is this possible? I may want to go for k up to say 50, ultimately I want to be able to go to k in the order of hundreds. Is it better to do this not with anonymous functions perhaps write a matlab function which calls itself recursively? or with f eval and a for lop that writes the entire string of commands for all the steps from 1 to k, with variable k?
Should I do this in another programming language, that is, would Matlab have fundamental limitations that could make such computation difficult? (and if so what could be the programming language that handles this best).
"Juan Miguel" wrote in message <email@example.com>...
> suppose I have a positive real number T, and I a have a vector of parameters "a" with N elements, and a function f(k,t) on t defined recursively in k, for k<N as follows
> (the following is NOT matlab code, it is just pseudo code to illustrate what I need to do, since i am not sure what Matlab data structure to use for the function)
> f(0,t) = 1 a constant for all t
> f(1,t) = @(t) integral( @(s) exp(-a(1)*s),t,T);
> f(2,t) = @(t) integral( @(s) f(1,s)*exp(-a(2)*s),t,T);
> f(k,t) =@(t) integral( @(s) f(k-1,s)*exp(-a(k-1)*s),t,T);
- - - - - - - -
It isn't necessary to do iteration (recursion) to find your f(n,t) for a given n. It can be expressed directly as a linear combination of n+1 exponential functions. The following matlab code evaluates numerically the necessary parameters for such an expression.
- - - - - -
% Let a be an n-element column vector
a = .05+.1*rand(10,1); % <-- Choose your 'a' vector
% Use a to compute the scalar b and n+1-element row vectors c and d.
n = size(a,1);
p = tril(reshape(1:n*(n+1),n,n+1));
p = p(p>0);
q = (n+1)*p-(n*(n+1)+1)*floor(p/(n+1));
M = cumsum(tril(repmat(a,1,n+1)));
c = M(n,:);
b = c(1);
M(q) = M(p);
d = prod(M).*((-1).^(0:n));
% Let T be a scalar and t an m-element vector
T = rand;
m = 100;
t = T-linspace(1,2,m);
% Compute the corresponding values of f(n,t) and plot it.
fn = zeros(size(t));
for ix = 1:m
fn(ix) = exp(-b*T)*sum(exp(c*(T-t(ix)))./d);
plot(t,fn,'y-') % <-- Plot of f(n,t) versus t
- - - - - -
For example the corresponding expression for f(3,t) would be this:
f(3,t) = exp(-(a1+a2+a3)*T) * ...
( +exp((a1+a2+a3)*(T-t))/a1/(a1+a2)/(a1+a2+a3) ...
where a1 = a(1), a2 = a(2), and a3 = a(3).
It is only fair to warn you that with a large value for n, even with double precision floating point accuracy, these numerical computations may encounter serious relative round off errors for values of t near T since it involves a linear combination of sizable exponential quantities whose sum should cancel out to nearly zero. The only remedy I can see for that is to use higher precision packages from the file exchange to do the equivalent of the above algorithm with the appropriate accuracy. If you try to carry this out using the symbolic toolbox, the expressions would have an order O(n^3) character-length which means that if n is in the hundreds, the expression would have a character-length in the millions!
One other warning for this algorithm is that no sequence of consecutive values from vector 'a' should have a sum of zero since that would yield an indeterminate ratio at some point which would result in a NaN value. That is, in the above example with n = 3, none of the values a1, a2, a3, a1+a2, a2+a3, and a1+a2+a3 can be zero.
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.
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.