如何使元素位于0.8到1和-0.8到-1之间的矩阵为正定 [英] How to make a matrix positive definite whose elements lie in the range 0.8 to 1 and -0.8 to -1

查看:120
本文介绍了如何使元素位于0.8到1和-0.8到-1之间的矩阵为正定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been given a positive definite matrix. Then I have modified the matrix in such a way that all the values of that matrix lie in the range 0.8 to 1 or -0.8 to -1. But after that the matrix no longer remain a positive definite matrix. I have used the

[R,p]=chol(NewMat)

功能来验证这一点.如何使修改后的矩阵为正定?

function to verify this. How will I make the modified matrix positive definite?

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.它的值在上述范围之间,但不是正定的.请帮忙.

Here I have modified the matrix read from the csv file. The modified matrix is NewMat. Its value lie between the above mentioned range, but it is not positive definite. Please help.

推荐答案

典型的问题是如何在不改变特征值和确定性的前提下修改矩阵.这通常是通过Givens轮换或Housholder减少来完成的.尽管通常以矩阵的三对角线形式讨论这些操作,但在了解如何将它们用于三对角线化之后,您可能可以将它们用于其他操作.

The typical question is how do you modify the matrix without altering its eigen values and thus its definiteness. This is typically done with Givens rotations or Housholder reduction. Although these operations are typically discussed in terms of tridiagonalization of a matrix you could likely use them to do other operations after seeing how they are used for tridiagonalization.

如果我想使n×n矩阵为正定,我通常会做类似A=rand(1024,8); A=A'*A;的操作,但是您的问题表明您想保留原始矩阵的某些未声明的属性.

If I want to make a n by n matrix positive definite I usually just do something like A=rand(1024,8); A=A'*A; But your question suggests that you want to preserve some unstated property of the original matrix.

这篇关于如何使元素位于0.8到1和-0.8到-1之间的矩阵为正定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆