How to calculate derivative and then apply limit in matlab

조회 수: 3 (최근 30일)
Ravikiran Mundewadi
Ravikiran Mundewadi 2020년 4월 22일
댓글: Ravikiran Mundewadi 2020년 4월 24일
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 CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by