find the initial value of a function - matlab

• Mar 24th 2009, 02:30 PM
hypokrit
find the initial value of a function - matlab
Hi all !

I have quite not very spectucular function http://www.gomatlab.de/images/smiles/icon_wink.gif and
I need to get with an initial value x(1), which I dont know yet, a sum of e.g. 10. I "programmed" a loop and find empirically an initial value of 9.47 to get a sum of 10 for this function (with 10 time steps). But this is either a sophisticated nor a mathematical solution.
here the function:

a=4 %phi, mean reversion
s=1 %local volatility
n=10 %years, time steps
x(1)=?

for i=2:n
x(i)=4*x(i-1)*s^2/(1+sqrt(1+4*x(i-1)*a*s^2))^2
end
out=sum(x)

Do you need bisections methods ? If yes, how I implement one for this ?
I am not a mathematicien so I would be very gratefull for any suggestions !
Thanks a lot in advance !
• Mar 24th 2009, 03:11 PM
CaptainBlack
Quote:

Originally Posted by hypokrit
Hi all !

I have not very spectucular function http://www.gomatlab.de/images/smiles/icon_wink.gif and
I need to get with an initial value x(1), which I dont know yet, a sum of e.g. 10. I "programmed" a loop and find empirically an initial value of 9.47 to get a sum of 10 for this function (with 10 time steps). But this is either a sophisticated nor a mathematical solution.
here the function:

a=4 %phi, mean reversion
s=1 %local volatility
n=10 %years, time steps
x(1)=?

for i=2:n
x(i)=4*x(i-1)*s^2/(1+sqrt(1+4*x(i-1)*a*s^2))^2
end
out=sum(x)

Do you need bisections methods ? If yes, how I implement one for this ?
I am not a mathematicien so I would be very gratefull for any suggestions !
Thanks a lot in advance !

Recode this as a function ff(x) where x will be the initial value and ff(x)=0 when your sum is 10. so something like this:

Code:

```function rv=ff(x0)     a=4 %phi, mean reversion   s=1 %local volatility   n=10 %years, time steps     x=zeros(1,10);   x(1)=x0;     for i=2:n     x(i)=4*x(i-1)*s^2/(1+sqrt(1+4*x(i-1)*a*s^2))^2   end     rv=sum(x)-10;```
Now you use a numerical root finder on this.

CB