读书笔记(八)
这是第八部分指数函数 复制代码即可运行 %% 指数函数与近似导数 a = 2; t = 0:.01:2; h = .00001; y = 2.^t; ydot = (2.^(t+h) - 2.^t)/h; plot(t,[y; ydot]) %一个自变量,两个因变量
%% 计算e format long format compact h = 1; while h > 2*eps %软件定义的很小的一个数 h = h/2; e = (1 + h)^(1/h); disp([h e]) %在命令行输出 end %% 计算e^t的另一种方法 t = rand %随机数 s = 1; term = 1; n = 0; r = 0; while r ~= s %判不等 r = s; n = n + 1; term = (t/n)*term; s = s + term; end exp_of_t = s %% 复利计算 r = 0.05; y0 = 1000; for t = 0:20 y1 = (1+r)^t*y0; y2 = (1+r/12)^(12*t)*y0; y3 = exp(r*t)*y0; plot(t,[y1 y2 y3],'*') %用星号绘图 hold on %绘图窗口不变 end
%% 汽车贷款 y0 = 20000 r = .10 h = 1/12 n = 36 p = (1+r*h)^n/((1+r*h)^n-1)*r*h*y0 %% 复数作指数 theta = (1:2:17)'*pi/8 z = exp(i*theta) p = plot(z); set(p,'linewidth',4,'color','red') %设置线性色彩 axis square off %横纵坐标等长,座标轴不显示
%% 欧拉公式 exp(i*pi) + 1