필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Solver 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