block does not fully set the dimensions of output 'ddtheta'
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello
I am trying to control dimming for 2 dof system, here is my problem:
Error:Block ''untitled/Subsystem/MATLAB Function'' does not fully set the dimensions of output 'ddtheta'.
Does anyone know how to fix this?
Here is my sctructure:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1691071/image.png)
Here is code inside MATLAB function:
function ddtheta = Robot_2_DOF(dtheta,theta,to)
m1=1;
m2=1;
l1=1;
l2=1;
g=9.81;
theta1=theta(1);
theta2=theta(2);
dtheta1=dtheta(1);
dtheta2=dtheta(2);
%% M
M=[((m1+m2)*l1^2+m2*l2^2+2*m2*l1*l2*cos(theta2)) m2*l2^2+m2*l1*l2*cos(theta2) ;...
m2*l2^2+m2*l1*l2*cos(theta2) m2*l2^2 ];
%% V
V=[-l1*l2*m2*sin(theta2)*(2*dtheta1*dtheta2^2) ;...
m2*l1*l2*dtheta1^2*sin(theta2)];
%% G
G=[(m1+m2)*g*l1*cos(theta1)+m2*g*l2*cos(theta2) ;...
m2*g*l2*cos(theta1+theta2)];
%% ddtheta
ddtheta=M/(to-V-G-dtheta);
0 comentarios
Respuestas (1)
Sam Chak
el 9 de Mayo de 2024
Hi @Peter
I'm not familiar with the specifics of your Robot dynamics, but based on my understanding of MATLAB, it seems that you should use a backslash operator (\) instead of a forward slash operator (/).
tspan = [0 2];
theta0 = [1 0];
[t, x] = ode45(@(t, theta) Robot_2_DOF(t, theta, 1), tspan, theta0);
plot(t, x), grid on
function ddtheta = Robot_2_DOF(t, theta, to)
m1 = 1;
m2 = 1;
l1 = 1;
l2 = 1;
g = 9.81;
theta1 = theta(1);
theta2 = theta(2);
dtheta1 = theta1;
dtheta2 = theta2;
%% M
M = [((m1+m2)*l1^2+m2*l2^2+2*m2*l1*l2*cos(theta2)) m2*l2^2+m2*l1*l2*cos(theta2) ;...
m2*l2^2+m2*l1*l2*cos(theta2) m2*l2^2 ];
%% V
V = [-l1*l2*m2*sin(theta2)*(2*dtheta1*dtheta2^2) ;...
m2*l1*l2*dtheta1^2*sin(theta2)];
%% G
G = [(m1+m2)*g*l1*cos(theta1)+m2*g*l2*cos(theta2) ;...
m2*g*l2*cos(theta1+theta2)];
%% ddtheta
ddtheta = M\(to - V - G - [dtheta1; dtheta2]); % <--- use backslash \
end
2 comentarios
Sam Chak
el 9 de Mayo de 2024
Hi @Peter
I don't have any issue running the corrected code (backslash) below. Are you sure that you are still getting the same Error: Block "MATLAB Function" does not fully set the dimensions of output 'ddtheta'? If that happens, most probably the initial values in your Integrator blocks are incorrectly set.
function ddtheta = Robot_2_DOF(theta, dtheta, to)
m1 = 1;
m2 = 1;
l1 = 1;
l2 = 1;
g = 9.81;
theta1 = theta(1);
theta2 = theta(2);
dtheta1 = dtheta(1);
dtheta2 = dtheta(2);
%% M
M = [((m1+m2)*l1^2+m2*l2^2+2*m2*l1*l2*cos(theta2)) m2*l2^2+m2*l1*l2*cos(theta2) ;...
m2*l2^2+m2*l1*l2*cos(theta2) m2*l2^2 ];
%% V
V = [-l1*l2*m2*sin(theta2)*(2*dtheta1*dtheta2^2) ;...
m2*l1*l2*dtheta1^2*sin(theta2)];
%% G
G = [(m1+m2)*g*l1*cos(theta1)+m2*g*l2*cos(theta2) ;...
m2*g*l2*cos(theta1+theta2)];
%% ddtheta
ddtheta = M\(to - V - G - dtheta);
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1691126/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1691131/image.png)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!