Finding x-axis crossing point for cumulative cash flow
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Sean de Wolski
on 12 Jul 2011
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 Comments
Andrei Bobrov
on 12 Jul 2011
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
Oleg Komarov
on 12 Jul 2011
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
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!