must return a column vector
1 view (last 30 days)
Show older comments
function ydot = assignment(t,y)
global l1 l2 F0 omega g
% Mass matrix
theta2dot=[1.8 (0.8.*l1)/l2;0.8 (0.8.*l1)/l2];
% Stiffness matrix
theta=[(1.8.*g)/l1;(0.8.*g)/l2];
% Calculate the coefficient matrix
MDK = theta2dot./theta;
A = [0 1 0 ;
0 0 1 ;
MDK(1,1) MDK(1,2) 0 ;
MDK(2,1) MDK(2,2) 0] ;
% Force vector
FVecor = [0; 0; F0.*sin(omega.*t);0];
% Output
ydot= A.*y-FVecor;0;
end
0 Comments
Answers (1)
Star Strider
on 16 Nov 2022
I am not certain what ‘ydot’ is supposed to be, however the element-wise multiplication is likely the problem.
Use array multiplication instead.
syms l1 l2 F0 omega g t y
y = sym('y',[3,1])
% global l1 l2 F0 omega g
% Mass matrix
theta2dot=[1.8 (0.8.*l1)/l2;0.8 (0.8.*l1)/l2];
% Stiffness matrix
theta=[(1.8.*g)/l1;(0.8.*g)/l2];
% Calculate the coefficient matrix
MDK = theta2dot./theta;
A = [0 1 0 ;
0 0 1 ;
MDK(1,1) MDK(1,2) 0 ;
MDK(2,1) MDK(2,2) 0] ;
% Force vector
FVecor = [0; 0; F0.*sin(omega.*t);0];
% Output
A*y-FVecor
ydot= A.*y-FVecor;0;
.
5 Comments
Star Strider
on 16 Nov 2022
Something is wrong with the code.
The ‘A’ matrix should be (4x4), however it is (4x3).
I am not certain what you are doing, so I can only point this out. You need to fix it.
%initialisation
% global l1 l2 F0 omega g
l1=0.3;
l2=0.2;
F0=10
omega=2
g=9.81
%set up the matrices
theta2dot=[1.8 (0.8*l1)/l2;0.8 (0.8*l1)/l2];
theta=[(1.8*g)/l1;(0.8*g)/l2];
%pre divide. this the blacklash operator
A=theta2dot.\theta;
%calculate the eigenvalues and eigenvectors of matrix A
[V, D]=eig(A)
clear
clc
% Assign parameters
% global l1 l2 F0 omega g
l1=0.3;
l2=0.2;
F0=10
omega=2
g=9.81
% Initial Conditions
% global x_0 theta1_0 theta2_0 xdot_0
x_0=0.15;
theta1_0=0.1*pi;
theta2_0=pi/4
xdot_0=0;
theta1dot_0=0;
theta2dot_0=0;
Y0=[x_0;theta1_0;theta2_0;xdot_0];
% Solve system of first order differential equations
% [t,y]=ode45('@assignment',[0 100],Y0 );
[t,y] = ode45(@(t,y)assignment(t, y, l1, l2, F0, omega, g),[0 100],Y0)
% Visualize
figure(1)
% Linear Displacement
plot(t,y(:,1))
xlabel('Time [s]')
ylabel('Displacement [m]')
figure(2)
% Angular Displacement
% Visualize
plot(t,y(:,2))
xlabel('Time [s]')
ylabel('Angular Displacement [m]')
function ydot = assignment(t, y, l1, l2, F0, omega, g)
y
% function ydot = assignment(t,y)
% global l1 l2 F0 omega g
% Mass matrix
theta2dot=[1.8 (0.8.*l1)/l2;0.8 (0.8.*l1)/l2];
% Stiffness matrix
theta=[(1.8.*g)/l1;(0.8.*g)/l2];
% Calculate the coefficient matrix
MDK = theta2dot./theta;
A = [0 1 0 ;
0 0 1 ;
MDK(1,1) MDK(1,2) 0 ;
MDK(2,1) MDK(2,2) 0]
% Force vector
FVecor = [0; 0; F0.*sin(omega.*t);0];
% Output
ydot=A*y-FVecor
% ydot=A.*y-FVecor;0;
end
.
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!