例2用循环语句编写M文件计算ex的值,其中x,n为输入 变量,θx的近似表达式为 ex≈1+x+一+—+∵ 2!3! function y=e(x, n) y=1;s=1 ⊙>y=e(1,100))调用函数 for j=l: n ans M文件 y=y+xIs y end 27183 y
例2 用循环语句编写M文件计算e x的值,其中x,n为输入 变量,e x的近似表达式为 2 3 1 2! 3! ! n x x x x e x n + + + + + function y=e(x,n) y=1;s=1; for i=1:n s=s*i; y=y+x^i/s; end y >> y=e(1,100) ans = y y = 2.7183 调用函数 M文件
MATLAB在《微积分》中的应用 2、求极限 例3求极限limn(Vn+√n-√n) n→>0 LIMIT Limit of an expression LIMIT(FX, a takes the limit of the symbolic expression F as x -> a LIMIT(F,X, a, rightor LIMIT(,x, a, left) specify the direction of a one-sided limit >>(syms n; 定义符号变量 >>limit(sqrt(n+sqrt(n))-sqrt(n),n, inf) ans =1/2
MATLAB在《微积分》中的应用 2、求极限 例3 求极限 lim( ) n n n n → + − >> syms n; >>limit(sqrt(n+sqrt(n))-sqrt(n),n,inf) ans = 1/2 LIMIT Limit of an expression. LIMIT(F,x,a) takes the limit of the symbolic expression F as x -> a. LIMIT(F,x,a,'right') or LIMIT(F,x,a,'left') specify the direction of a one-sided limit. 定义符号变量