I encountered error while running program(runga kutta solving using function handle) for solving a set of differential equations and applying a controller 'u'. How to tackle it out?

조회 수: 2 (최근 30일)
matrix dimension doesn't match in line 86 while solving the attached file 'abc'
  댓글 수: 2
SHIJINA P P
SHIJINA P P 2016년 7월 21일
I want out(4,i) to be an array, but when that is used in u (via sdot), error occurs, Is it due due the presence of 'u' in function handle?
Geoff Hayes
Geoff Hayes 2016년 7월 21일
u appears to be used on a line following the one that generates the error. If you use the MATLAB debugger, what do you see?

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

답변 (1개)

Geoff Hayes
Geoff Hayes 2016년 7월 21일
Shijina - use the MATLAB debugger to step through the code and see what is happening. Consider these lines which initializes a variable named out as
x=[21900;301.4*2;0;0;2*pi/180;0];
out( :,1)=x;
and so out is a 6x1 array. Now, in your for loop, you do some work and then update out as
out(:,i+1)=x;
and so out is now a 6x2 array. The problem is with line 86
sdot=(1/d)*(-out(4,:)-(rho*A*out(2,:)*Cl/(2*m)-(g/out(2,:)-...
out(2,:)/(R+out(1,:)))*cos(out(3,:)))-rho*A*out(2,:)*Cl/(2*m)-(g/out(2,:)-...
out(2,:)/(R+out(1,:)))*cos(out(3,:))-lambda*(rho*(out(2,:))^2*A*D/(2*I)*(-...
Cm+Cmq*D*out(4,:)/out(2,:))))
Look how out is used. On the first iteration, when out is a 6x1 array, out(4,:) is a scalar as are all other instances where we access this variable. But on the subsequent iteration of the loop, out(4,:) (and the others) will be 1x2 arrays. Is this what you want? Or do you just want the scalar from the previous iteration i.e.
out(4,i)
were i is the indexing variable in your for loop.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by