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?

4 次查看(过去 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 中查找有关 Function Creation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by