How would I ask the user to input another option for cash flow and interest rate, then compare the two or three additional options?
1 view (last 30 days)
Show older comments
clc;
clear;
close all;
numberYears= input('Planning Horizon Length\n--> ');
cashflows = zeros(numberYears, 1);
for k = 1:numberYears
cashflows(k) = input(sprintf('Cash flow for year %d\n--> ', k));
end
n=length(cashflows);
for i =1:n
x(i) = i-1;
end
ir = input('Input Interest Rate (%)\n-->');
PW= 0;
i = (ir/100)+1;
bar(x,cashflows,0.25)
%Equation for PW analysis
for j= 1:length(i)
PW=0;
for t= 1:n
PW=PW+cashflows(t)*i(j)^(-x(t));
PWA(j,t)=PW;
end
end
%plots CF diagram
figure(1)
hold on
plot(x,PWA,'-x','LineWidth',2)
legend('Cash Flow',num2str(ir),'Location','southeast')
% plot your data
ylabel('Present Worth')
xlabel('Year')
check1 = PWA(end)>0;
answer = ['N','Y'];
fprintf('Is the investment worthwhile? %c\n',answer(check1+1))
It should also ouptut which option is best
0 Comments
Answers (0)
See Also
Categories
Find more on Cash Flows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!