problem with vectors and dimensions

Good evening! I tried to solve this algorithm in script file
and Cn from this Table
and p is we will neglect it . I will use this vector for (a) (just for test )
a=[1 -0.2 3.005 -39608 - 0.0985 1.2311];
and at the end I must to get this result (note; RD=R)
I used this Matlab code
% code
a=[1 -0.2 3.005 -39608 - 0.0985 1.2311];
n=length(a);
Ck = [[-16 0 20 0 -5 0] [8 0 -8 0 1] [-4 0 3 0] [2 0 -1] [-1 0]]; %%%Cn
switch n
case 1
R=0;
w=[1 7 12 16 19 0];
p=[6 11 15 18 20 0];
for i=1:n+1 ;
R=R+(a(i)*Ck(w(i):p(i)));
end
case 2
R=0;
w=[1 7 12 16 19 0];
p=[6 11 15 18 20 0];
for i=1:n+1 ;
R=R+(a(i)*Ck(w(i):p(i)));
end
case 3
R=0;
w=[1 7 12 16 19 0];
p=[6 11 15 18 20 0];
for i=1:n+1 ;
R=R+(a(i)*Ck(w(i):p(i)));
end
case 4
R=0;
w=[1 7 12 16 19 0];
p=[6 11 15 18 20 0];
for i=1:n+1 ;
R=R+(a(i)*Ck(w(i):p(i)));
end
case 5
R=0;
w=[1 7 12 16 19 0];
p=[6 11 15 18 20 0];
for i=1:n+1 ;
R=R+(a(i)*Ck(w(i):p(i)));
end
otherwise
disp('high order')
end
and i got error because the dimensions are different between the vectors and i used {switch .. case } because in the future i want to Enter different values of (a) and with different lengths (I want to build algorithm working with any values of (a)) .
please if anyone can help me to find the another solution (but without use any function from symbolic toolbox functions because my target is solve it without symbolic math toolbox ) Thank you

回答 (1 件)

ANKUR KUMAR
ANKUR KUMAR 2018 年 1 月 9 日

1 投票

You are getting an error in this line
R=R+(a(i)*Ck(w(i):p(i)));
The dimension of R is 1*6 and dimension of (a(i)*Ck(w(i):p(i))) is 1*5 How can you add the matrices of different dimension.

3 件のコメント

laith ismail
laith ismail 2018 年 1 月 9 日
thank you for replay the dimension of Ck is changing with every step because if you see the Eq above related with Ck its depend on the number of K or n (because these are same ) and i know there are problems with the dimension but how can i solve it ? this the question and if you have some advise please tell me .
ANKUR KUMAR
ANKUR KUMAR 2018 年 1 月 10 日
What is the purpose of adding these R. There may be some logic behind this. Instead of adding, you can store every R in call format by using R{i}.
Walter Roberson
Walter Roberson 2018 年 1 月 10 日
Pad the shorter one with leading zeros before doing the addition.

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

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

製品

質問済み:

2018 年 1 月 9 日

コメント済み:

2018 年 1 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by