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

2 Kommentare

It would be interesting to know what F is.
Just added that bit to the top of the code block

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Torsten
Torsten am 20 Apr. 2022
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 Kommentar

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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2021b

Gefragt:

am 20 Apr. 2022

Kommentiert:

am 20 Apr. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by