Differentiation with symbolic function giving NaN value upon repeatedly executing

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

 采纳的回答

And why don't you simply evaluate
exp(z^2)/(z-3) at z=2 to get the residual at z=2 and
exp(z^2)/(z-2) at z=3 to get the residual at z=3 ?

1 个评论

I wanted to automate the entire process so that a general function could be made. If that proves to not be possible, I will have to go for this approach.
Thank you!

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

产品

版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by