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?

1 vue (au cours des 30 derniers jours)
matrix dimension doesn't match in line 86 while solving the attached file 'abc'
  2 commentaires
SHIJINA P P
SHIJINA P P le 21 Juil 2016
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 le 21 Juil 2016
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?

Connectez-vous pour commenter.

Réponses (1)

Geoff Hayes
Geoff Hayes le 21 Juil 2016
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.

Catégories

En savoir plus sur Function Creation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by