用Octave计算函数极限(1)
广告
{{v.name}}
计算\(\displaystyle\lim_{n \to \infty}n(\frac{\pi}{2} - {\rm arctan}n)\)
程序代码如下
function [text_result, numeric_result] = func1(n_value)
pkg load symbolic;
n = sym('n');
question = n * (pi / 2 - atan(n));
lim = limit(question, n, n_value);
text_result = ["\n", disp(lim)];
numeric_result = eval(lim);
endfunction
令\(n \to \infty\),计算结果如下
>> [text_result, numeric_result] = func1(inf)
warning: passing floating-point values to sym is dangerous, see "help sym"
warning: called from
double_to_sym_heuristic at line 50 column 7
sym at line 384 column 13
minus at line 47 column 5
func1 at line 4 column 14
text_result =
1
numeric_result = 1
令\(n \to 2\),计算结果如下
>> [text_result, numeric_result] = func1(2)
warning: passing floating-point values to sym is dangerous, see "help sym"
warning: called from
double_to_sym_heuristic at line 50 column 7
sym at line 384 column 13
minus at line 47 column 5
func1 at line 4 column 14
text_result =
π - 2⋅atan(2)
numeric_result = 0.9273
可见符号解和数值解有可能不同。