error when trying to calculate a limit with double variable.

2 ビュー (過去 30 日間)
Jéssica Martins
Jéssica Martins 2020 年 11 月 10 日
コメント済み: Jéssica Martins 2020 年 11 月 10 日
When I execute the following code :
n=linspace(10,10e20);
un=(1+1./n).^n;
limit(un,n,inf);
It returns the following error: Undefined function 'limit' for input arguments of type 'double'.
can anyone help me get the value of the limit on matlab ?

採用された回答

James Tursa
James Tursa 2020 年 11 月 10 日
編集済み: James Tursa 2020 年 11 月 10 日
limit( ) operates on symbolic expressions. E.g.,
>> syms n
>> limit((1+1/n)^n,inf)
ans =
exp(1)
For the numerical approximation, you can't use a number that is too large or the sum will have too much cancellation error. Double precision has about 15 digits, so you should stay under that to get any meaningful results. E.g.,
>> n = 1e10;
>> (1+1/n)^n % <-- 1/n contributes to the sum 1+1/n
ans =
2.718282053234788 % <-- reasonable approximation
>> exp(1)
ans =
2.718281828459046
>> n = 1e20;
>> (1+1/n)^n % <-- 1/n does not contribute to the sum 1+1/n
ans =
1 % <-- bad approximation
  1 件のコメント
Jéssica Martins
Jéssica Martins 2020 年 11 月 10 日
thank you so much ! you just save my work!

サインインしてコメントする。

その他の回答 (1 件)

David Hill
David Hill 2020 年 11 月 10 日
Use symbolic for limit function.
syms n;
un = (1+1/n)^n;
limit(un,n,inf);

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by