Demo entry 6720752

matlab

   

Submitted by anonymous on Mar 18, 2018 at 03:48
Language: Matlab. Code size: 594 Bytes.

%根据各个参数计算每月的钱的函数
%参数:Start		 起始的金额
%      In				前几月每月存入的钱
%			 InMonth	存入钱持续的月数
%			 Out			后几月每月取出的钱
%			 Interest 每月利息
%			 MaxMonth 计算最大月数,注意!!MaxMonth应大于InMonth
%
%返回:Money		 每月的金额
%			 Month		持续的月数
function [Money,Month] = MoneyCal(Start,In,InMonth,Out,Interest,MaxMonth)
Money = [];
Money(1) = Start;

Month = 1;
for i = 1 : InMonth
	Month = Month + 1;
	Money(Month) = Money(Month - 1) * (1 + Interest) + In;
end

for i = 1 : (MaxMonth - InMonth)
	Month = Month + 1;
	Money(Month) = Money(Month - 1) * (1 + Interest) - Out;
	if Money(Month) <= 0
		break;
	end
end

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).