Unable to multiply a matrix in loop with a matrix without loop?

Unable to execute u * q , where q and p are matrices of hermite polynomials. kindly help me..
clc; clear all
%
format rat
syms t
M = [0 2 0 0; 0 0 4 0; 0 0 0 6; 0 0 0 0];
u = [0 0 0 0; 0 1/12 0 0; 0 0 1/6 0; 0 0 0 1/4];
%
for t =[0 1/3 2/3 1]
p= hermiteH(0:3, t);
q= hermiteH(0:3, t/2);
disp ( p*M- u * q )
end

回答 (1 件)

KSSV
KSSV 2017 年 4 月 3 日

0 投票

You see your matrices are not obeying rule of matrix multiplication. The below works according to the dimensions of matrices.
format rat
syms t
M = [0 2 0 0; 0 0 4 0; 0 0 0 6; 0 0 0 0];
u = [0 0 0 0; 0 1/12 0 0; 0 0 1/6 0; 0 0 0 1/4];
%
for t =[0 1/3 2/3 1]
p= hermiteH(0:3, t);
q= hermiteH(0:3, t/2);
disp ( p*M- (u * q')' )
end

5 件のコメント

R shah
R shah 2017 年 4 月 3 日
what is meant and purpose by the prime on q?
R shah
R shah 2017 年 4 月 4 日
編集済み: Stephen23 2017 年 4 月 4 日
Let me try to show again what i want to do.
clc; clear all
format rat
syms t
M = [0 2 0 0; 0 0 4 0; 0 0 0 6; 0 0 0 0];
u =[1/4 1/4 1/4 1/4];
%
for t =[0 1/3 2/3 1]
p= hermiteH(0:3, t);
q= hermiteH(0:3, t/2);
w= diag(u);
end
disp (w)
i want to multiply the output matrix w with the q matrix which is in loop, how can i do so . the answer of w * q is;
1/4 0 -1/2 0
1/4 1/12 -17/36 -53/108
1/4 1/6 -7/18 -25/27
1/4 1/4 -1/4 -5/4
i am new in MATLAB kindly help what should i do?
Stephen23
Stephen23 2017 年 4 月 4 日
@R shah: please tell us the exact output of these commands:
size(w)
size(q)
R shah
R shah 2017 年 4 月 4 日
w and q both are of size 4x4

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2017 年 4 月 3 日

コメント済み:

2017 年 4 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by