Differentiation with symbolic function giving NaN value upon repeatedly executing
Show older comments
I am manually finding the residues at the poles of a complex function but when I execute this code in a for loop, or copy and paste it as I have done below, it works once and then just starts to output NaN. I know the code below is an unorganised approach, I had split it up this way only to debug.
I have tried to fix this for hours and have made no progress.
Any help would be greatly appreciated!!
syms Z
F = @(Z) ((exp(Z^2))/((Z-2)*(Z-3)))
sum_of_res = 0
current_pt = sings(1) %sings is the array of singular pts/poles
% using formula for residues
res1_fn = ((1/factorial(0))*diff(((Z-current_pt)^1)*F(Z), Z))
%replace 1 by m
Z = current_pt
c = subs(res1_fn) %this is done because res1_fn has to be evaluated at the pole (current_pt) after diff
sum_of_res = sum_of_res + c
disp(res1_fn)
% substituting z0 in the res function
% finding residues at singularity number 2
current_pt = sings(2)
Z = current_pt
% using formula for residues
res2_fn = ((1/factorial(0))*diff(((Z-current_pt)^1)*F(Z), sym('Z')))
%replace 1 by m
Z = current_pt
c = subs(res2_fn)
sum_of_res = sum_of_res + c
disp(res2_fn)
% substituting z0 in the res function
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!