Inverse of matrix is wrong?

20 vues (au cours des 30 derniers jours)
Shayma Al Ali
Shayma Al Ali le 3 Nov 2021
I have a 583x583 matrix called "F". I am trying to use F to get a variable X for an equation FX=B. However, when I solve for X, the results do not seem correct and have negative values. When looking at the matrix F, I noticed that both codes:
X=inv(F)*B and X=F\B
yield the same results. However, I don't think that the inverse of F is correct beacuse when I multiply F by inv(F), I do not get the identity matrix. What could be the possible result of that?
The code used to construct the matrix F:
val=zeros(1,583);
j=[10,10E-1,10E-2,(9:-1:1)*(10^-3)];
val(1:12)=j;
sum_val=sum(val_norm); val_norm=val/sum_val; %normalize the function
F=toeplitz(val_norm,[val_norm(1), zeros(1,numel(val_norm)-1 )]);
and to check that X=inv(F)*B and X=F\B are the same
B=rand(583,1);
X1=inv(F)*B
X2=F\B
  2 commentaires
the cyclist
the cyclist le 3 Nov 2021
Your code to create F gives an error:
val=zeros(1,583);
j=[10,10E-1,10E-2,(9:-1:1)*(10^-3)];
val(1:12)=j;
sum_val=sum(val_norm); val_norm=val/sum_val; %normalize the function
Unrecognized function or variable 'val_norm'.
F=toeplitz(val_norm,[val_norm(1), zeros(1,numel(val_norm)-1 )]);
I can think of ways to fix it, but I dont want to inadvertently create a different value of F than you are.
Shayma Al Ali
Shayma Al Ali le 3 Nov 2021
Modifié(e) : Shayma Al Ali le 3 Nov 2021
Sorry it should be like this:
val=zeros(1,583);
j=[10,10E-1,10E-2,(9:-1:1)*(10^-3)];
val(1:12)=j;
sum_val=sum(val); val_norm=val/sum_val; %normalize the function
F=toeplitz(val_norm,[val_norm(1), zeros(1,numel(val_norm)-1 )]);

Connectez-vous pour commenter.

Réponses (1)

the cyclist
the cyclist le 3 Nov 2021
Looks fine to me:
val=zeros(1,583);
j=[10,10E-1,10E-2,(9:-1:1)*(10^-3)];
val(1:12)=j;
sum_val=sum(val); val_norm=val/sum_val; %normalize the function
F=toeplitz(val_norm,[val_norm(1), zeros(1,numel(val_norm)-1 )]);
shouldBeIdentityMatrix = F*inv(F);
identityMatrix = eye(583);
maxError = max(abs(shouldBeIdentityMatrix(:)-identityMatrix(:)))
maxError = 1.1102e-16
The maximum error between the calculated identity matrix F*inv(F) and the theoretical identify matrix is of the order of computational roundoff error.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by