フィルターのクリア

How to solve this warning: Matrix is close to singular or badly scaled

1 回表示 (過去 30 日間)
Atinesh Singh
Atinesh Singh 2016 年 11 月 14 日
回答済み: Walter Roberson 2016 年 11 月 14 日
I'm trying to implement a Evolutionary Strategy algorithm (an optimization algorithm). On increasing the size of the parameter nx from 3 onwards, I'm getting warning
nx = 3
Warning: Matrix is singular to working precision.
nx >= 4
Warning: Matrix is close to singular or badly scaled
At this line
alphar{i}(p,m) = alphar{i}(p,m) - 2*pi*(alphar{i}(p,m)/abs(alphar{i}(p,m)));
Complete Code is attached below

採用された回答

Walter Roberson
Walter Roberson 2016 年 11 月 14 日
Change
[p,m] = find(abs(alphar{i}) > pi);
alphar{i}(p,m) = alphar{i}(p,m) - 2*pi*(alphar{i}(p,m)/abs(alphar{i}(p,m)));
to
ind = find(abs(alphar{i}) > pi);
alphar{i}(ind) = alphar{i}(ind) - 2*pi*(alphar{i}(ind) ./ abs(alphar{i}(ind)));
Your find is returning multiple locations. That results in a vector of p and a vector of m. When you access alphar{i} with two vectors as coordinates, the result is not the array accessed at just the individual locations (p(K), m(K)) for K = 1 : length(p) : the result is submatrices, exactly like if you had asked for
A([3, 8], [9, 2])
meaning to access the submatrix [A(3,9), A(3,2); A(8, 9), A(8,2)]
Even after you correct for that by using the linear indices instead of the subscript pairs, you have a matrix / a matrix, which is like Array * inv(Array) -- algebraic matrix division. But you want the locations to act independently, so you need the ./ operator not /

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by