"Error using vertcat Dimensions of arrays being concatenated are not consistent." why this error showing?

1 次查看(过去 30 天)
function M = mass(t,q)
% Mass matrix function
M = zeros(4,4);
M(1,1) = 1;
M(2,2) = 1;
M(3,3) = 1;
M(4,2) = 1;
M(4,4) = 1;
end
function dqdt = my_ode(t,q)
%% Conversion to first order parameters
% y = q(1); %% displacement of damper
% ydot = q(2); %% velocity of damper
% yddot = q(2)dot; %% acceleration of damper
% z = q(3); %% displacement of structure
% zdot = q(4); %% velocity of structure
% zddot = q(4)dot; %% acceleration of structure
% q = [q(1) q(2) q(3) q(4)]; %% Output parameters
% tspan = i; %% Time span
%% Initial inputs
m1 = 200; %% mass of the structure(kg)
k1 = 15; %% stiffness of the structure(N/m)
c1 = 5; %% damping of the structure(Ns/m)
k2 = 150; %% stiffness of the damper(N/m)
R = 0.5; %% Radius of the tank(m)
h = 0.05; %% Height of liquid in tank(m)
g = 9.81; %% Acceleration due to gravity(m/s^2)
A = 0.05; %% Amplitude of ground displacement(m)
f = 1; %% Input frequencycy(Hz)
rho = 1000; %% Density of fluid(Kg/m^3)
xi = 1.841; %% First derivative of the Bessel function for first mode
fs = 1.111; %% Frequency of structure(Hz)
n = 1; %% Tuning ratio
nu = 10^-6; %% Kinematic viscosity of water(m^2/s)
t = 0:0.1:20; %%Time span
%% Mass of the damper
m2 = ((pi*rho*R^3)/2.2)*tanh(xi*h/R);
%% Damping coefficient of damper
c2 = ((5.78*sqrt(m2*k2))/pi)*sqrt(nu/((R)^1.5*(g)^0.5))*(1+((0.318/sinh(xi*h/R))*(1+((1-h/R)/cosh(xi*h/R)))));
%% structure frequency
w1 = 3.48;
%% damper frequency
w2 = sqrt(xi*g*tanh(xi*(h/R))/R);
%% define damping factor of damper
r2 = c2/(2*m2*w2);
%% define damping factor of structure
r1 = 0.01;
%% define mass ratio
barm = (((R^3*pi*rho)/(2.2))*tanh(xi*(h/R)))/(m1);
%% define ground acceleration
ugdd = A*sin(2*pi*f*t);
%% Equation to solve
dqdt = [q(2)
(-2*r1*w1*q(2))-((w1)^2*q(1))+(2*r2*w2*barm*q(4))+(barm*(w2)^2*q(3))-ugdd
q(4)
-ugdd-(2*r2*w2*q(4))-((w2)^2*q(3))];
clc;
clear all;
%% To run mass spring damper system
tspan = 0:0.1:20;
q = [0 0 0 0];
opts = odeset('Mass',@(t,q) mass(t,q));
%% Solve using ode45
[tsol,qsol] = ode45(@(t,q)my_ode(t,q),tspan,q,opts);
%% plotting
plot(tsol,qsol(:,1))
xlabel('time(sec)')
ylabel('displacement(m)')
grid on
title('displacement response of structure')
figure
plot(tsol,qsol(:,2))
xlabel('time(sec)')
ylabel('velocity(m/s)')
grid on
title('Velocity response of structure')

回答(1 个)

Torsten
Torsten 2022-3-24
function "my_ode" lacks an "end" statement.
  6 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by