如何制作矩阵正定,其元素位于0.8到1和-0.8到-1的范围内

时间:2014-05-01 09:08:41

标签: matrix linear-algebra matlab matlab-figure

我得到了一个正定矩阵。然后我修改了矩阵,使得该矩阵的所有值都在0.8到1或-0.8到-1的范围内。但在此之后,矩阵不再是正定矩阵。我用过

[R,p]=chol(NewMat)

验证这一点的功能。如何使修正矩阵为正定?

clc
clf
clear all
close all
Matrix=csvread('new1.csv'); %reading the csv file.
fid1 = fopen('new2.csv');
X = textscan(fid1, '%s%s%s%s%f%f%f', 'Delimiter', ',');
fclose(fid1);
FirstCol = X{1, 1};
SecondCol=X{1,2};
ThirdCol=X{1,3};
FourthCol=X{1,4};
%the factors by which numbers are changed
f1=9.5;
f2=4.75;
f3=3.15;
f4=2.36;
f5=1.9;
f6=1.58;
f7=1.35;
f8=1.18;
flag=1;
p=0;
row=size(Matrix,1);%number of rows in the Matrix
col=size(Matrix,2);%number of columns in the Matrix
NewMat=double(zeros(row,col));
%Factoring the elements of the matrix. The while loop runs until all the
%values lie in the range 0.8<+ve value<1 and -1<-ve value<-0.8

while(flag)
    for i=1:row
        for j=1:col
            if abs(Matrix(i,j))>0 && abs(Matrix(i,j))<=0.1
                NewMat(i,j)=Matrix(i,j)*f1;      
            elseif abs(Matrix(i,j))>0.1 && abs(Matrix(i,j))<=0.2
                NewMat(i,j)=Matrix(i,j)*f2;
            elseif abs(Matrix(i,j))>0.2 && abs(Matrix(i,j))<=0.3
                NewMat(i,j)=Matrix(i,j)*f3;
            elseif abs(Matrix(i,j))>0.3 && abs(Matrix(i,j))<=0.4
                NewMat(i,j)=Matrix(i,j)*f4;
            elseif abs(Matrix(i,j))>0.4 && abs(Matrix(i,j))<=0.5
                NewMat(i,j)=Matrix(i,j)*f5;
            elseif abs(Matrix(i,j))>0.5 && abs(Matrix(i,j))<=0.6
                NewMat(i,j)=Matrix(i,j)*f6;
            elseif abs(Matrix(i,j))>0.6 && abs(Matrix(i,j))<=0.7
                NewMat(i,j)=Matrix(i,j)*f7;
            elseif abs(Matrix(i,j))>0.7 && abs(Matrix(i,j))<=0.8
                NewMat(i,j)=Matrix(i,j)*f8;
            else
                NewMat(i,j)=Matrix(i,j);
            end
        end
    end

    Matrix=NewMat;
    for i=1:row
        for j=1:col
            if (abs(NewMat(i,j))<0.8 || abs(NewMat(i,j))>1)
                flag=1;
                p=1;
            end
        end
    end


    if p==0
    flag=0;
    end
    p=0;
end
%error checking, so that the number remains in the range -1 to +1. If the
%number is not within this range, you can see an error message
for i=1:row
    for j=1:col
        if NewMat(i,j) <-1 || NewMat(i,j) >1
            disp('Error: the number is out of bounds.')
        end
    end
end

这里我修改了从csv文件中读取的矩阵。修改后的矩阵是NewMat。它的值介于上述范围之间,但不是肯定的。请帮忙。

1 个答案:

答案 0 :(得分:0)

典型的问题是如何在不改变其特征值的情况下修改矩阵,从而修改矩阵的确定性。这通常通过Givens轮换或Housholder减少来完成。虽然这些操作通常是根据矩阵的三对角化来讨论的,但在看到它们如何用于三维对角化之后,您可能会使用它们进行其他操作。

如果我想制作一个n×n矩阵正定,我通常只做A=rand(1024,8); A=A'*A;之类的但是你的问题表明你想要保留原始矩阵的一些未说明的属性。