Simple matlab code issue

2 ビュー (過去 30 日間)
Leora
Leora 2014 年 9 月 16 日
コメント済み: Youssef Khmou 2014 年 9 月 16 日
I have an issue with a very basic code using matrices. I had to define 3 matrices and do a few operations. I got them all correct except for the last one. It says the dimensions don't match but that is what the question is telling me to do. Any help would be appreciated.
A=[1,2,3;4,5,6;7,8,9]; %Defining matrices A,B and C B=[2,8,2;1,1,1;7,0,2]; C=[2;0;1]; A+B A.*B transpose(C)*B inv(A)*(C).^1 B+(C).^2
The last one is incorrect and the question asks me to do B+C^2
  1 件のコメント
Leora
Leora 2014 年 9 月 16 日
The error says error using + dimensions must agree

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

回答 (2 件)

Youssef  Khmou
Youssef Khmou 2014 年 9 月 16 日
編集済み: Youssef Khmou 2014 年 9 月 16 日
The quantity (C')*B*inv(A)*(C).^1 is scalar, and B+C.^2 is not correct :
B+(C*C').^2;
is correct
  2 件のコメント
Leora
Leora 2014 年 9 月 16 日
But my code says B+C.^2 and its still wrong
Youssef  Khmou
Youssef Khmou 2014 年 9 月 16 日
the answer is edited .

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


Hikaru
Hikaru 2014 年 9 月 16 日
B is a 3x3 matrix and C.^2 is a 3x1 matrix. There's no way you can add them. If you want to square matrix C (i.e. C^2), then C has to be a square matrix as well.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by