开元食味
德国频道
楼主: quantum
打印 上一主题 下一主题

自编买房贷款小程序

[复制链接]
11#
发表于 27.4.2003 15:01:02 | 只看该作者
function loan2()

% the program to calculate the loan interest and time to pay the loan

interest=0.0496;
month_pay=1393.33;
total_loan=220000;
tilgung0=(month_pay*12-total_loan*interest)/total_loan;
tilgung0

rest(1)=1;

for ii=1:4000
rest(ii+1)=rest(ii)-((interest+tilgung0)/12-rest(ii)*interest/12);
if rest(ii+1)<=0
iii=ii+1;
break;
end
end

s=0;
for ii=1:iii
s=s+rest(ii);
end
s=s/iii*interest;
s
end


fp=fopen('loan2.out','w');
for ii=1:iii
fprintf(fp,'%f %fn',ii,rest(ii));
end
fclose(fp);

第27行的end(红)好像不需要写,但我也不是很确定,不过出来的结果是一样的,只是少了warning.
12#
 楼主| 发表于 28.4.2003 09:54:39 | 只看该作者
呵呵,帮你确定一下,你是对的,偷懒一拷贝,确实少删了一个end。
另外第12行的ii=1:4000只需要1:600就够了,会快得多;我因为计算机快,随便放了个大数目上去,也没认真改。 smile.gif
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

站点信息

站点统计| 举报| Archiver| 手机版| 小黑屋

Powered by Discuz! X3.2 © 2001-2014 Comsenz Inc.

GMT+1, 19.4.2024 10:04

关于我们|Apps

() 开元网

快速回复 返回顶部 返回列表