Hello, I wrote a program today for a HW assignment in one of my courses and I'm getting an unusual answer from it. The program uses residue to give me the residues, poles and extra terms for the expanded function, or if I give it the r,p,k it will give me the original function. My code is below, keep in mind I've got little experience programming:
strResponse = input('0 = r,p,k from B(s)/A(s), 1 = opposite : '); disp(' ') if strResponse == 0
n = input('Does A, B or A and B need expanded? [a,b,ab,N with apostrophes]: '); syms s y;
if n == 'N' B = input(' B = '); A = input(' A = '); elseif n == 'a' As = expand(input('Type A in terms of s: ')); A = sym2poly(As) B = input(' B = '); elseif n == 'b' By = expand(input('Type B in terms of y (swap for s): ')); B = sym2poly(By) A = input(' A = '); elseif n == 'ab' As = expand(input('Type A in terms of s: ')); A = sym2poly(As) Bs = expand(input('Type B in terms of s: ')); B = sym2poly(Bs) end
[r,p,k] = residue(B,A)
else r = input(' r = '); p = input(' p = '); k = input(' k = ');
[B,A] = residue(r,p,k) end
The problem arises when I try to expand: 6 / ((s^2 + 1)*(s^2 +36)) It gives me non-real answers for the residues and poles, whereas if I do the expansion by hand I get real answers for residues and poles (and the correct answer).