Inverse of matrix is wrong?

32 visualizzazioni (ultimi 30 giorni)
Shayma Al Ali
Shayma Al Ali il 3 Nov 2021
Risposto: the cyclist il 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 Commenti
the cyclist
the cyclist il 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 il 3 Nov 2021
Modificato: Shayma Al Ali il 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 )]);

Accedi per commentare.

Risposte (1)

the cyclist
the cyclist il 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.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by