Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to fit with an infinite serie function ?

Subject: How to fit with an infinite serie function ?

From: Aurelie Chabaud

Date: 9 Jul, 2010 10:00:21

Message: 1 of 9

I would like to fit non-linear data points I have collected from FRAP experiments. The function to be fitted is an infinite serie :
f = Somme (((-b)^n/factorial(n))/(1+n*(1+2*t/tauD))) with n=1 to 100
I need to find the best value for my parameters b and tauD.

I have tried to use the curve fitting tool but the function was not accepet as custom equation.

I'm totally novice in matlab so I would be pleased if someone could help me.

Subject: How to fit with an infinite serie function ?

From: John D'Errico

Date: 9 Jul, 2010 11:24:04

Message: 2 of 9

"Aurelie Chabaud" <aurelie.billon@univ-nantes.fr> wrote in message <i16rvl$hmf$1@fred.mathworks.com>...
> I would like to fit non-linear data points I have collected from FRAP experiments. The function to be fitted is an infinite serie :
> f = Somme (((-b)^n/factorial(n))/(1+n*(1+2*t/tauD))) with n=1 to 100
> I need to find the best value for my parameters b and tauD.
>
> I have tried to use the curve fitting tool but the function was not accepet as custom equation.
>
> I'm totally novice in matlab so I would be pleased if someone could help me.

ARGH! Don't do it.

100 terms of this series will yield numerical garbage.

factorial(100)
ans =
  9.3326e+157

Remember, that you are working in FLOATING POINT
ARITHMETIC, in double precision. So you have about
16 digits of accuracy to work with. No more.

As a rough guess, any more than about 5 terms of this
series is probably a waste of time.

John

Subject: How to fit with an infinite serie function ?

From: Walter Roberson

Date: 9 Jul, 2010 19:15:48

Message: 3 of 9

John D'Errico wrote:
> "Aurelie Chabaud" <aurelie.billon@univ-nantes.fr> wrote in message
> <i16rvl$hmf$1@fred.mathworks.com>...
>> I would like to fit non-linear data points I have collected from FRAP
>> experiments. The function to be fitted is an infinite serie :
>> f = Somme (((-b)^n/factorial(n))/(1+n*(1+2*t/tauD))) with n=1 to 100
>> I need to find the best value for my parameters b and tauD.
>>
>> I have tried to use the curve fitting tool but the function was not
>> accepet as custom equation.
>>
>> I'm totally novice in matlab so I would be pleased if someone could
>> help me.
>
> ARGH! Don't do it.
>
> 100 terms of this series will yield numerical garbage.
>
> factorial(100)
> ans =
> 9.3326e+157
>
> Remember, that you are working in FLOATING POINT
> ARITHMETIC, in double precision. So you have about
> 16 digits of accuracy to work with. No more.
>
> As a rough guess, any more than about 5 terms of this
> series is probably a waste of time.

Unfortunately the sum is divergent for some values of b, t, and tauD . In
particular, when tauD is near -2*t then the difference between the sum to 100
and the sum to 101 can range from -infinity to +infinity, and so the sum
cannot be truncated.


A symbolic summation to infinity can be done, yielding
-b * tauD *
hypergeom( [1, (2*tauD+2*t)/(tauD+2*t)],
            [2, (3*tauD+4*t)/(tauD+2*t)],
            -b) /
(2*tauD+2*t)

This has poles at tauD = -t and at tauD = -2*t .

It thus seems to me that the fitting will have no solution, not unless tauD is
constrained (e.g., to be the same sign as t).

Subject: How to fit with an infinite serie function ?

From: Roger Stafford

Date: 9 Jul, 2010 21:57:03

Message: 4 of 9

"Aurelie Chabaud" <aurelie.billon@univ-nantes.fr> wrote in message <i16rvl$hmf$1@fred.mathworks.com>...
> I would like to fit non-linear data points I have collected from FRAP experiments. The function to be fitted is an infinite serie :
> f = Somme (((-b)^n/factorial(n))/(1+n*(1+2*t/tauD))) with n=1 to 100
> I need to find the best value for my parameters b and tauD.
>
> I have tried to use the curve fitting tool but the function was not accepet as custom equation.
>
> I'm totally novice in matlab so I would be pleased if someone could help me.
- - - - - - - - - -
  Provided your t satisfies abs(2*t/tauD) < 1, and regarding your series as an infinite series rather than stopping at n = 100, this series is absolutely convergent and defines an analytic function of t in that circle in the t-complex plane. As you may know, even though the series may be divergent outside this circle, such analytic functions can usually be analytically continued to other regions beyond the circle of convergence. That is apparently true in your case.

  Walter has provided you with that analytic function using the generalized hypergeometric function. This can serve as an alternative method of evaluating your f quantity rather than having to perform the summation. Even though 'hypergeom' is capable of performing numeric computation, it is contained in the symbolic toolbox, so you would need that toolbox.

  As Walter points out, you will have to stay well away from the two poles at t = -tauD and t = -tauD/2.

Roger Stafford

Subject: How to fit with an infinite serie function ?

From: Roger Stafford

Date: 10 Jul, 2010 00:45:06

Message: 5 of 9

  In my previous posting I should have said that Walter's generalized hypergeometric solution is analytic in the variable b and has an infinite radius of convergence in b, (though I believe it is also analytic in t as well.) It remains as an alternate method of evaluating the infinite series. Also it remains true that t must be kept away from -tauD and -tauD/2.

Roger Stafford

Subject: How to fit with an infinite serie function ?

From: Bruno Luong

Date: 10 Jul, 2010 08:39:04

Message: 6 of 9

I must miss something, the factorial(n) term in the denominator grow faster than any other terms (see Stirling approximation formula) so it looks like to me the series converges regardless the value of t or b.

It seems that the various denominator terms in Walter's hypergeometric formula is just be there due to formal calculus, but does not matter when we looks at the original series.

Incidentally me and my students have to deal with some nasty series of Hypergeometric functions (not hypergeometric series) last week in our optic simulation code. We use the fortran code we download from somewhere else and it is very slow to evaluate. Finally we gives up that approach for various reasons, and prefer a more brute-force method.

To Aurelie: You can program the series (or hypergeometric function, but you should double check where there is really a singular poles) inside a customized function, and call the fit function. As John's pointed out FACTORIAL part can give infinity when more terms in the series is considered, so be careful. Personally I don't believe it causes any numerical problem because it's on the denominator. See example here

http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/lsqcurvefit.html

I presume you fit "f" for various "t". The function should very much like this

function f = myfun(x,t)
b = x(1);
tauD = x(2);
f = 0;
for n=1:100
    f = f + (-b).^n ./ (factorial(n)*(1+n*(1+(2/tauD)*t)));
end
end

The invoke lsqcurvefit: like this

x = lsqcurvefit(@myfun,x0, t, ft)

Where x0 is the 2x1 vector first guess of b and tauD, t is vector of abscissa, and ft are the corresponding data.

Bruno

Subject: How to fit with an infinite serie function ?

From: Roger Stafford

Date: 10 Jul, 2010 16:54:05

Message: 7 of 9

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i19bj8$563$1@fred.mathworks.com>...
> I must miss something, the factorial(n) term in the denominator grow faster than any other terms (see Stirling approximation formula) so it looks like to me the series converges regardless the value of t or b.
>
> It seems that the various denominator terms in Walter's hypergeometric formula is just be there due to formal calculus, but does not matter when we looks at the original series.
>
> Incidentally me and my students have to deal with some nasty series of Hypergeometric functions (not hypergeometric series) last week in our optic simulation code. We use the fortran code we download from somewhere else and it is very slow to evaluate. Finally we gives up that approach for various reasons, and prefer a more brute-force method.
>
> To Aurelie: You can program the series (or hypergeometric function, but you should double check where there is really a singular poles) inside a customized function, and call the fit function. As John's pointed out FACTORIAL part can give infinity when more terms in the series is considered, so be careful. Personally I don't believe it causes any numerical problem because it's on the denominator. See example here
>
> http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/lsqcurvefit.html
>
> I presume you fit "f" for various "t". The function should very much like this
>
> function f = myfun(x,t)
> b = x(1);
> tauD = x(2);
> f = 0;
> for n=1:100
> f = f + (-b).^n ./ (factorial(n)*(1+n*(1+(2/tauD)*t)));
> end
> end
>
> The invoke lsqcurvefit: like this
>
> x = lsqcurvefit(@myfun,x0, t, ft)
>
> Where x0 is the 2x1 vector first guess of b and tauD, t is vector of abscissa, and ft are the corresponding data.
>
> Bruno
- - - - - - - - - -
  Yes, Bruno, my aging brain went sadly astray on that problem. The series will indeed converge for any b and for any t for which -tauD/(tauD+2*t) is not a positive integer. There should be poles in the t complex plane at each of these latter t values.

  I do feel that Aurelie should give matlab's 'hypergeom' function in the symbolic toolbox a chance to see what it can do. If Mathworks has written it properly, it could well be much superior to summing the series. After all, this is no different in principle from evaluating many other transcendental functions such as sine, exponential, logarithm, etc. except that more parameters are involved, and I think matlab-ers would be very reluctant to have to evaluate these latter by their infinite series.

Roger Stafford

Subject: How to fit with an infinite serie function ?

From: Bruno Luong

Date: 10 Jul, 2010 19:02:05

Message: 8 of 9

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i1a8jd$nbi$1@fred.mathworks.com>...

> Yes, Bruno, my aging brain went sadly astray on that problem. The series will indeed converge for any b and for any t for which -tauD/(tauD+2*t) is not a positive integer. There should be poles in the t complex plane at each of these latter t values.

In general, you are still very sharp Roger, one of the sharpest people in this newsgroup IMO.

>
> I do feel that Aurelie should give matlab's 'hypergeom' function in the symbolic toolbox a chance to see what it can do. If Mathworks has written it properly, it could well be much superior to summing the series. After all, this is no different in principle from evaluating many other transcendental functions such as sine, exponential, logarithm, etc. except that more parameters are involved, and I think matlab-ers would be very reluctant to have to evaluate these latter by their infinite series.
>

We do try the hypergeometric function from Mathematica and the later seems to to be well implemented. Unfortunately we develop out code with Matlab.

I think Aurelie should give both a try.

Bruno

Subject: How to fit with an infinite serie function ?

From: Roger Stafford

Date: 11 Jul, 2010 07:32:04

Message: 9 of 9

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i1ag3d$kuu$1@fred.mathworks.com>...
> In general, you are still very sharp Roger, one of the sharpest people in this newsgroup IMO.
> ......
> Bruno
- - - - - - - -
  Thank you for the compliment, Bruno. I return it by saying you are one of the people on cssm I have the most trouble keeping up with. You often publish a brilliant solution to a difficult problem when I am still stumbling around with it, or worse, when I've already put out a dumb solution. You make me wish I were young again.

Roger Stafford

Tags for this Thread

What are tags?

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.

Contact us