How to multiply an inverse matrix (nxn) by an array (nx1) using for loop

4 ビュー (過去 30 日間)
Gabriel Sheets
Gabriel Sheets 2022 年 2 月 8 日
編集済み: James Tursa 2022 年 2 月 8 日
I am new to Matlab and am trying to figure out an alternative way to multiply an inverse matrix J (2x2) by some f (2x1) other than using J\f. Here is what I have so far, however when I run it, it says that H is an unrecognized function or variable:
J_inv=inv(J);
for i=1:iter
H(J_inv,f)=J_inv*f;
end
Thanks in advance!

回答 (1 件)

James Tursa
James Tursa 2022 年 2 月 8 日
Not sure why you have a for-loop at all. Maybe you can explain this. If you just want to multiply the explicit inverse by a vector, just do it:
J_inv = inv(J);
f = your column vector
H = J_inv * f;
  3 件のコメント
Gabriel Sheets
Gabriel Sheets 2022 年 2 月 8 日
It definitely is not the most efficient way but a way nonetheless.
James Tursa
James Tursa 2022 年 2 月 8 日
編集済み: James Tursa 2022 年 2 月 8 日
If you want a loop, then this outline:
m = size(J_inv,1); % number of rows of J_inv
for k=1:m
H(k) = ____; % insert dot product of J_inv k'th row and f vector here
end
I've left a bit of coding for you to do.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by