problem with vectors and dimensions

조회 수: 9 (최근 30일)
laith ismail
laith ismail 2018년 1월 9일
댓글: Walter Roberson 2018년 1월 10일
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일
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
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by