Error using horzcat CAT arguments dimensions are not consistent

조회 수: 2 (최근 30일)
Lia
Lia 2013년 5월 2일
Hello everyone,
I have a M-file that I am going to invoke in another M-file to solve an ordinary differential equation. The file I am having trouble with is setting up the ODE to be solved. Here is the code:
function dy = dydtsys(tspan,y)
% given properties
g = 9.81; % acceleration due to gravity
l = 0.50; % length of each segment
p = 6500; % density of each segment
b = .05; % dimension of square cross section
m = l*(b*b)*p; % mass
Ic = m*l*l/12; % moment of inertia
theta1 = y(1); % angle of slider one
thetad1 = y(2); % angular velocity of slider one
theta2 = y(3); % angle of slider two
thetad2 = y(4); % angular velocity of slider two
xdd = @(tspan)((-4.2/2)*sin(4.2*tspan)); % slider acceleration
% Set up matrix A and vector b
A = [(Ic+((5/4)*m*(l^2))) ((1/2)*m*(l^2)*(cos(theta1-theta2)));...
((1/2)*m*(l^2)*(cos(theta1-theta2))) (Ic + ((1/4)*m*l*l))];
b = @(tspan) -[(((3/2)*m*(l*xdd(tspan))*(cos(theta1)))+((1/2)*(m*l*l)* (sin(theta1-theta2))*...
(thetad2.^2))+((3/2)*(m*g*l)*(sin(theta1))));...
(((1/2)*(m*l*xdd(tspan))*(cos(theta2)))-((1/2)*(m*l*l)*(sin(theta1-theta2))...
*(thetad1.^2))+((1/2)*(m*g*l)*(sin(theta2))))];
% A and b are the equations of motion based on Newton's second law
thetadd = @(tspan) A\b(tspan); % angular acceleration of each link
dy = [y(2) thetadd(1) y(4) thetadd(2)]';
end
The error is occuring in line 29:
dy = [y(2) thetadd(1) y(4) thetadd(2)]';
Any help is greatly appreciated! Thank you for your time,
Lia
  댓글 수: 1
Matt Kindig
Matt Kindig 2013년 5월 2일
This is strange, since anyvector(1) should return only one element.
Try this: assign thetadd(1) to a variable (e.g., "t1"). What is the size() and class() of t1?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by