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
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.