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 回表示 (過去 30 日間)
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 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by