Inverse of matrix is wrong?
22 次查看(过去 30 天)
显示 更早的评论
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
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
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.
回答(1 个)
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(:)))
The maximum error between the calculated identity matrix F*inv(F) and the theoretical identify matrix is of the order of computational roundoff error.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!