目录
指数函数及e
指数增长
复数指数
练习
1. expgui
2. 计算e
3 五角星绘制
指数函数及e
(1)的比值总是常数
(2)的导数为其自身。(根据比值=1推导出e的值)
%% Plot a^t and its approximate derivativea = 2;t = 0:.01:2;h = .00001;y = 2.^t;ydot = (2.^(t+h) - 2.^t)/h;plot(t,[y; ydot])legend('y','dy/dx')
%% Compute eformat longformat compacth = 1;while h > 2*epsh = h/2;e = (1 + h)^(1/h);disp([h e])end
对指数函数进行二项式展开,求和式的每一项都通过前一项简单计算得出。该循环在r==s时结束,即两个相连的部分浮点数相同时结束。
%% Experimental version of exp(t)t = rands = 1;term = 1;n = 0;r = 0;while r ~= sr = s;n = n + 1;term = (t/n)*term;%求和式的每一项都通过前一项简单计算得出s = s + term;endexp_of_t = s
指数增长
年利、月利、连续利息
%% Compound interestfprintf(' t yearly monthly continuous\n')format bankr = 0.05;y0 = 1000;for t = 0:20y1 = (1+r)^t*y0;y2 = (1+r/12)^(12*t)*y0;y3 = exp(r*t)*y0;disp([t y1 y2 y3])end
贷款清还
%% Payments for a car loany0 = 20000r = .10h = 1/12n = 36p = (1+r*h)^n/((1+r*h)^n-1)*r*h*y0
复数指数
绘制八边形
%% Complex exponentialtheta = (1:2:17)'*pi/8z = exp(i*theta)p = plot(z);set(p,'linewidth',4,'color','red')axis square off
练习
1. expgui
2. 计算e
%% 计算e
%在h很小时,10的负多少次方不能由浮点数很好表示,将会发生偏差
clear
format long
format compact
h=1
while h>1.e-15h=h/10; e=(1+h)^(1/h); disp([h e])
end%% 计算e
clear
format long
format compact
h=1
while h>1.e-15h=h/10; e=(1+h)^(1/(1+h-1)); disp([h e])
end
3 五角星绘制
%% 利用复数指数绘制五角星theta = (0:3:15)'*(2*pi/5)z = exp(i*theta)p = plot(z);set(p,'linewidth',4,'color','red')axis square off