problem with vectors and dimensions
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
ANKUR KUMAR
am 9 Jan. 2018
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 Kommentare
ANKUR KUMAR
am 10 Jan. 2018
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}.
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!