Filter löschen
Filter löschen

How to calculate derivative and then apply limit in matlab

12 Ansichten (letzte 30 Tage)
Ravikiran Mundewadi
Ravikiran Mundewadi am 22 Apr. 2020
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...

Antworten (2)

Deepak Gupta
Deepak Gupta am 22 Apr. 2020
Bearbeitet: Deepak Gupta am 23 Apr. 2020
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 Kommentare
Ameer Hamza
Ameer Hamza am 23 Apr. 2020
Bearbeitet: Ameer Hamza am 23 Apr. 2020
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 am 23 Apr. 2020
This is one of those situations where limitations of MATLAB symbolic toolbox become visible.

Melden Sie sich an, um zu kommentieren.


Ameer Hamza
Ameer Hamza am 23 Apr. 2020
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 Kommentare
Ameer Hamza
Ameer Hamza am 24 Apr. 2020
I am glad to be of help.
Ravikiran Mundewadi
Ravikiran Mundewadi am 24 Apr. 2020
Be in touch... Thank you...

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by