Finding x-axis crossing point for cumulative cash flow

Hi,
I had a small set of data that has years (1-25) and cumulative cash flow (-200,000 to 10,000). I want to find where the line crosses the x-axis and therefore showing the payback period. However, I'm stuck :-(. I can't using interp1 as that returns the y value for a value of x. Fzero also doesn't appear to be an option as I don't know the function. Any help guys? I'm 99% sure I sound really stupid in this question, so apologies..
Thanks again..

2 commentaires

Post all 25 cash flows here (formatting with the {} button)
David
David le 12 Juil 2011
[-£116,549.62 -£109,094.93 -£101,763.22 -£94,558.85 -£87,485.51 -£80,546.27 -£73,743.62 -£67,079.54 -£60,555.51 -£54,172.58 -£47,931.42 -£41,832.31 -£35,875.20 -£30,059.75 -£34,816.97 -£29,282.74 -£23,887.62 -£18,630.31 -£13,509.36 -£8,523.15 -£3,669.93 £1,052.19 £5,645.19 £10,111.16 £14,452.25]

Connectez-vous pour commenter.

Réponses (1)

What about fzero with interp1 as the engine of the function?
EDIT per comment Not really; N does not need to be large.
Example:
x_pts = 1:7; %sample x values
y_pts = -5:2:7; %sample y values
f = @(x)interp1(x_pts,y_pts,x,'linear','extrap'); %must be able to extrapolate
fzero(f,6)
%find where the interpolation yields zero.

3 commentaires

David
David le 12 Juil 2011
Ah, okay. So if I use something like y=interp1(year,cumulative,N), where N is a large enough array to interpolate across. I have, however, got a few problems with the fzero function, as in that I'm unsure of how to turn the above y function into an actual MATLAB function to use in the fzero line. I'm pretty new at this game, hence the slowness.
data = [-116549.62 -109094.93 -101763.22 -94558.85 -87485.51 -80546.27 -73743.62 -67079.54 -60555.51 -54172.58 -47931.42 -41832.31 -35875.20 -30059.75 -34816.97 -29282.74 -23887.62 -18630.31 -13509.36 -8523.15 -3669.93 1052.19 5645.19 10111.16 14452.25];
>>f = @(x)interp1(0:length(data)-1,data,x,'linear','extrap')
f =
@(x)interp1(0:length(data)-1,data,x,'linear','extrap')
>> fzero(f,15)
ans =
20.7771784706869
f = @(x)interp1(1:11,data(15:end),x,'linear','extrap')
plot(1:25,data,'-b',fzero(f,0) + 14,0,'or')
fzero + 14 = 21.7772

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Question posée :

le 12 Juil 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by