user967493
user967493

Reputation: 143

left side division: transfering from matlab to scilab

I'm trying to implement some filter fitting routines in Scilab which are already inherent to Matlab. I'm trying to compute filter coefficients through a least Squares algorithm as in invfreqz.m. To realize that I have to compute a left side matrix division on some nearly singular matrices. Problem is that Scilab yields different results from this calculation than matlab and I can't fix the problem. The code is the following:

matrix = [336.1810  331.8898  331.8898  336.1810  331.8898; 331.8898  336.1810  320.9743  331.8898  336.1810; 331.8898  320.9743  336.1810  331.8898  320.9743; 336.1810  331.8898  331.8898  336.1810  331.8898; 331.8898  336.1810  320.9743  331.8898  336.1810];
vector = [-331.8898; -320.9743; -336.1810; -331.8898;  -320.9743];
result = matrix \ vector;

Matlab gives me the result:

result =
 -0.5078
  0.5078
 -1.0000
  0.5078
 -0.5078

and Scilab yields:

result  =
  0.00000000000000050  
  0.                   
- 0.99999999999999856  
  0.                   
- 0.00000000000000219  

Performing the calculation with both software gives me the warning:

> Warning: Matrix is close to singular or badly scaled.

with different rcond values

matlab: RCOND =  1.703907e-17
Scilab: rcond=   0.0000D+00

I checked Matlab's invfreq.m and they do it exactly the same way, but the results differ from Scilab. Even the warning shows as well. :) Now I need to obtain the same result in Scilab but I can't find a workaround because I have no clue what's going on. Anybody might have an idea or even a solution?

Upvotes: 0

Views: 135

Answers (3)

Serge Steer
Serge Steer

Reputation: 446

If a problem is ill conditionned as yours, there is no numerical algorithm able to provide accurate results.

The error on A\B operation can be estimated by

 norm(B)*%eps*cond(A)

Upvotes: 1

user967493
user967493

Reputation: 143

In case a future reader happens to get in the same situation: i composed a testing transfer function that accidentially resulted in a singular matrix, that can not be solved with certainty with the algorithm found in invfreqz.m. For those who are interested, the algorithm roots in a paper called "complex curve fitting" written by E.C. Levy

Upvotes: 1

hiandbaii
hiandbaii

Reputation: 1331

The result is numerically unstable. You shouldn't put any stock in either answer.

Upvotes: 2

Related Questions