Error using horzcat CAT arguments dimensions are not consistent

2 views (last 30 days)
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 Comment
Matt Kindig
Matt Kindig on 2 May 2013
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?

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!