Error using horzcat Dimensions of arrays being concatenated are not consistent.
3 views (last 30 days)
Show older comments
Not sure why I'm recieving this error for this code:
h= 0.1;
t0= 0;
y1=-0.25;
tEnd=2;
T=[t0:h:tEnd];
N=20;
Y=zeros(N+1,1);
%solving with Taylor series
for i=1:N
Y1= sin(4*T);
Y2= 4*cos(4*T);
Y3= -16*sin(4*T);
Y4= -64*cos(4*T);
Y(i+1)= Y(i) + Y1(i)*h + (Y2(i)/2)*h^2 + (Y3(i)/6)*h^3 + (Y4(i)/24)*h^4;
end
>> [T,Y]
0 Comments
Answers (1)
Star Strider
on 9 Jan 2020
The reason is that ‘T’ is a (1x21) row vector, and ‘Y’ is a (21x1) column vector.
The (:) subscript convention forces ‘T’ to become a column vector here, so the concatenation works:
Result = [T(:),Y]
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!