Inverse of matrix is wrong?

20 ビュー (過去 30 日間)
Shayma Al Ali
Shayma Al Ali 2021 年 11 月 3 日
回答済み: the cyclist 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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by