例2用循环语句编写M文件计算ex的值,其中x,n为输入 变量,e的近似表达式为 2 3 xX X e≈1+x+++…+ 2!3 function y=e(x, n) y=1;s=1 y=(100)调用函数 for j=l: n ans〓 M文件 S=S y=ytxils; end 27183
例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求极限lim(Vn+Ⅶn-n) n→ LIMIT Limit of an expression LIMIT(,x, a takes the limit of the symbolic expression F asX→a LIMIT(X, a,right")or 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. 定义符号变量