How to calculate derivative and then apply limit in matlab

5 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linear Programming and Mixed-Integer Linear Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by