How to calculate derivative and then apply limit in matlab

6 ビュー (過去 30 日間)
Ravikiran Mundewadi
Ravikiran Mundewadi 2020 年 4 月 22 日
How to calculate diff((x/(exp(x)-1)),x,n) and then apply the limit at x=0 Where n=11,12,13,14,15 I am getting upto 1 to 10 but not from 11 onwards... please anybody help me...

回答 (2 件)

Deepak Gupta
Deepak Gupta 2020 年 4 月 22 日
編集済み: Deepak Gupta 2020 年 4 月 23 日
Hi Ravikiran,
I have used a for loop.
syms f(x) x;
f(x) = x/(exp(x)-1);
g = f;
limitg = sym(zeros(15, 1));
for n = 1:15
g = diff(g);
limitg(n) = limit(g, x, 0);
end
Code may throw error of "Devide by Zero".
Thanks,
Deepak
  18 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 4 月 23 日
編集済み: Ameer Hamza 2020 年 4 月 23 日
I get the same answer, with or without simplify(). I am using R2020a, and from recent questions on this forum, I have noticed that they have improved Symbolic toolbox in this release.
syms x
y = x/(exp(x)-1);
for i=1:15
Dy = simplify(limit(diff(y, i), x, 0));
if Dy == 0
fprintf('i = %d,\t Dy = 0\n', i);
else
[n, d] = rat(Dy);
fprintf('i = %d,\t Dy = %d/%d\n', i, n, d);
end
end
Result:
i = 1, Dy = -1/2
i = 2, Dy = 1/6
i = 3, Dy = 0
i = 4, Dy = -1/30
i = 5, Dy = 0
i = 6, Dy = 1/42
i = 7, Dy = 0
i = 8, Dy = -1/30
i = 9, Dy = 0
i = 10, Dy = 5/66
i = 11, Dy = 0
i = 12, Dy = 0
i = 13, Dy = 0
i = 14, Dy = 0
i = 15, Dy = 0
Ameer Hamza
Ameer Hamza 2020 年 4 月 23 日
This is one of those situations where limitations of MATLAB symbolic toolbox become visible.

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


Ameer Hamza
Ameer Hamza 2020 年 4 月 23 日
As discussed in the comment to Deepak's answer. This is a limitation of of MATLAB's symbolic engine. MATLAB calculates the limit for n-th order derivatives for n>10 to be zero
syms x
y = x/(exp(x)-1);
for i=1:15
Dy = simplify(limit(diff(y, i), x, 0));
if Dy == 0
fprintf('i = %d,\t Dy = 0\n', i);
else
[n, d] = rat(Dy);
fprintf('i = %d,\t Dy = %d/%d\n', i, n, d);
end
end
Result
i = 1, Dy = -1/2
i = 2, Dy = 1/6
i = 3, Dy = 0
i = 4, Dy = -1/30
i = 5, Dy = 0
i = 6, Dy = 1/42
i = 7, Dy = 0
i = 8, Dy = -1/30
i = 9, Dy = 0
i = 10, Dy = 5/66
i = 11, Dy = 0
i = 12, Dy = 0
i = 13, Dy = 0
i = 14, Dy = 0
i = 15, Dy = 0
But Wolfram Alpha is able to calculate the limit: https://www.wolframalpha.com/input/?i=limit+x-%3E0+d%5E12%2Fdx%5E12+x%2F%28e%5Ex-1%29. Even this FEX submission by John: https://www.mathworks.com/matlabcentral/fileexchange/20058-adaptive-numerical-limit-and-residue-estimation is not able to converge to a limit. I guess there is nothing much you can do about in MATLAB, other than writing your own closed-form solution if it is possible.
  5 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 4 月 24 日
I am glad to be of help.
Ravikiran Mundewadi
Ravikiran Mundewadi 2020 年 4 月 24 日
Be in touch... Thank you...

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

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by