problem with vectors and dimensions
9 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
ANKUR KUMAR
2018-1-9
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 个评论
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}.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!