LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

MathScript/LabVIEW residue bug

Try this in MathScript:

>>bb = [6 -8];
>>aa = [1 -1 -6];
>>[r,p,k] = residue(bb, aa)
r =      4   
           2   
p =     -2    
           3
k =      0    

Then multiply both the numerator and denominator by z:

>>bb = [6 -8 0];
>>aa = [1 -1 -6 0];
>>[r,p,k] = residue(bb, aa)
r =      -8   
           6   
p =     -2    
           3
k =      0 

Wow, you get a different, wrong answer.  Matlab returns the same answer in both cases.

Take this a step further and use the Partial Fraction Expansion VI.  It gives the same wrong answer!

What's up?
0 Kudos
Message 1 of 3
(8,188 Views)
Further investigation shows that the error in in the Partial Fraction Expansion VI which is called by residue.vi.

--Mark
0 Kudos
Message 2 of 3
(8,185 Views)
Hi Mark,
 
You've located a problem with the LabVIEW MathScript function 'residue'.
 
With your example

>>bb = [6 -8 0];
>>aa = [1 -1 -6 0];
>>[r,p,k] = residue(bb, aa)

the problem arises when the parameters bb and aa describe polynomials that are multiples of 'z' and have a nontrivial greatest common divisor:

bb represents 6z^2-8*z

aa represents z^3-z^2-6z

As you noted, the problem occurs due to an underlying problem in Partial Fraction Expansion, a VI from the LabVIEW function palette (Mathematics->Polynomial->Rational Polynomial) that is being called "under-the-hood" when you invoke the LabVIEW MathScript 'residue' command.

One way to avoid this problem is to do pole-zero cancellation before applying 'residue'

Alternatively, you can perturb aa or bb slightly by adding some small constant terms, for instance:

>>bb=[6 -8 1e-6]

The problems described here are something that our engineers are aware of and are planning to fix in a future release.

--Sam

Sam Shearman
0 Kudos
Message 3 of 3
(8,147 Views)