function res=myrese(exprz,z)
% myres figure out residues of a function of complex variables
%
% Input changeable1exprz = The expression of the function and specified variable
% 2z = The singular point which residue you want to know
% (Enter when you just want that point
% Output The singular points and corresponding residuessymbolic object
% formatin a matrix with two rows,the first row is singular points,the
% seceond row is correspoind residues.
% Example: res=myrese('1/(z*(z+1)),z');res=myrese('cot(z),z');res=myres('1/z,z','0');res=myres('cos(z),z');
% res=myrese('z,z');
% Note Every argument must be character!
% Physical Science and technology College of Central China Normal
% University Grade 2005 Pu Ke Nov.4th.2006
if nargin==0
error('No argument!');
elseif nargin==1
maple('interface(warnlevel=0);myresidue := proc (ex, z) Sing := singular(ex, z); n := nops({Sing}); if n = 0 then ERROR("No singular point!") elif n = 1 then resi := residue(ex, Sing[1]) elif 1 < n then resi := [seq(r[I], I = 1 .. n)]; for k to n do resi[k] := residue(ex, Sing[k][1]) end do end if; return Sing, resi end proc:');
[cha,chan,chay]=command(exprz);
num=str2double(maple(chan));
try
inter=maple(cha);
if isempty(strfind(inter,'residue'))%The'residue'appears imply that maple can't find the residue
if isempty(strfind(inter,'_Z1'))==0
error('problem');
else
res=condition1(inter,num);
end
elseif isempty(strfind(inter,'residue'))==0&&isempty(strfind(inter,'_Z1'))
disp('Cant figure out the residue. The singular points are:');
maple(chay)
res=[];
else
error('problem');%Throw a exception
end
catch%Deal with the situation that there are infinite singular points.
res=condition2(chay,num,exprz);
end
elseif nargin==2
com=['residue(',exprz,'=',z,')'];
res=[simple(sym(z));sym(maple(com))];
end
maple('restart');%clear the memory of the worksheet
end
function [cha,chan,chay]=command(exprz)%Call maple function
cha=['myresidue(',exprz,')'];
chan=['nops({singular(',exprz,')})'];%The number of singular point
chay=['singular(',exprz,')'];%singular point
end
function res=condition1(inter,num)
indexe=strfind(inter,'=');
indexh=strfind(inter,'}');
index=max(strfind(inter,'}'));
sing=sym(zeros(1,num));
for k=1:length(indexe)
sing(k)=simple(sym(inter(indexe(k)+1:indexh(k)-1)));
end
res=[sing;simple(sym(inter(index+3:length(inter))))];%convert charater to MATLAB symbolic object.
end
function res=condition2(chay,num,exprz)
if num==0
disp('There is no singular point finite area!');
res=sym('0');
else
disp('This function have infinite singular point. they are:')
maple(chay)
z=input('Please choose a singular point:z=');
z=num2str(z);%conver it to charater
com=['residue(',exprz,'=',z,')'];
res=[sym(z);simple(sym(maple(com)))];%convert charater to MATLAB symbolic object.
end
end