Inverse of matrix is wrong?

22 次查看(过去 30 天)
Shayma Al Ali
Shayma Al Ali 2021-11-3
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 个评论
the cyclist
the cyclist 2021-11-3
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 2021-11-3
编辑:Shayma Al Ali 2021-11-3
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 )]);

请先登录,再进行评论。

回答(1 个)

the cyclist
the cyclist 2021-11-3
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.

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by