习题2.2.4 - 1

题目

1.如果在240个月内每月付款300美元,求解满足全部年金 A A A为500,000美元的利率 I I I的近似值(精确到小数点后10位)。

#代码

 %习题2.2.4.1
%如果在240个月内每月付款300美元,
%求解满足全部年金为50000美元的利率I的近似值
%(精确到小数点后10位)
%初值a, b选择: 
%a=0.1575, f=-280.8919
%b=0.1576, f=433.9995
function Proj_2_2()
f=@(I) 300/I*12*((1+I/12)^240-1)-500000 ;%P=300,N=240,A=500000 f=P/I*12*((1+I/12)^N-1)-Aa=0.15;
b=0.16;
%找初值
% for k=1:10
%     I+0.0001*k
%     feval(f,I+0.0001*k)
% end
delta=5*10^(-11);
%用二分法计算近似值
I=bisect(f,a,b,delta)%0.157 539 310 2 88429
end%二分法
function [c,err,yc]=bisect(f,a,b,delta)
%Input  - f is the function input as a string 'f'
%       - a and b are the left and right end points
%       - delta is the tolerance
%Output - c is the zero
%       - yc=f(c)
%       - err is the error estimate for c
ya=feval(f,a);
yb=feval(f,b);
if ya*yb>0,disp('choose another a and b'),return,end
max1=1+round((log(b-a)-log(delta))/log(2));
for k=1:max1c=(a+b)/2;yc=feval(f,c);if yc==0a=c;b=c;elseif yb*yc>0b=c;yb=yc;elsea=c;ya=yc;endif b-a<delta, break,end
end
c=(a+b)/2;
err=abs(b-a);
yc=feval(f,c);
end


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部