ode45 not enough

2 Ansichten (letzte 30 Tage)
Sophie Scott
Sophie Scott am 16 Nov. 2022
Beantwortet: SANKALP DEV am 7 Sep. 2023
Hello,
there is 3 things i am trying to achieve:
  1. Fleg as a function of time
  2. components of the force (x and y), Fx = Flegsin45 & Fy = Flegcos45
  3. max amplitude of response
I keep getting the same argument that there is not enough input arguments for my function.
i have attached the code i am currently trying to use:
function ydot=Q3func(t,y)
% Define global variables which will be used in the other functions
global t0 M C K D F U Fd Fi omega phi ;
Fleg= (3/4)*Fd*(sin(omega*t+phi)-sin(3*omega*t+(3*phi))/3) + Fi*cos((omega*t)+phi);
% FX = Fleg(t)*sin(45)
% FY = Fleg(t)*cos(45)
% Force=[0; 0; 0; 0; 0; 0]';
end
% ydot=D*y+Force;
this is to be used with:
%% Inputs
global t0 M C K D F U Fd Fi omega phi ;
m= 9000000; % mass = 9000 tonnes (kg)
Ig = 1.35*10^9; % Inertia (kgm^2)
I = 0.1198; % I=pi/4(do^4-di^4)(m^4)
E = 200*10^9; % Young's modulus, 200 GPa (Pa)
L = 20; % 20:5:50 = 10-40m including deck to sea level
k = (3*E*I)/(L^3); % stiffness
l1 = 16; % Lengths to centre of mass (m)
l2 = 14;
l3 = 17;
l4 = 13;
omega = 1.57;
phi = 5.25;
Fd = 3;
Fi = 60;
%% Creating Matrices
% The mass, stiffness, and damping matirces M, K and C and amplitude of force F. We are using proportional damping
M = [m 0 0;0 m 0; 0 0 Ig];
K = [4*k 0 2*k*(l1-l2);0 4*k 2*k*(l4-l3);2*k*(l1-l2) 2*k*(l4-l3) 2*k*(l1^2+l2^2)+2*k*(l3^2+l4^2)];
C=0.2*K;
% F = [Fxa+Fxb+Fxc+Fxd ; Fya+Fyb+Fyc+Fyd ; (Fxa+Fxb)*l1-(Fxc+Fxd)*l2-(Fya+Fyd)*l3+(Fyb+Fyc)*l4];
F = [1;2;3];
%% Transforming 3x3 EOM into 6x6 EOM with D and U(t)
zeromatrix=zeros(3,3);
identmatrix=eye(3,3);
zeromatrix2=zeros(1,3);
D=[zeromatrix identmatrix;-inv(M)*K -inv(M)*C];
U=[zeromatrix2;-inv(M)*F];
%% Setting the ICs & time
t0=4; % Define period of the waves... Period of first sea state
y0=[0 0 0 0 0 0]; % Set up initial displacement and velocity to zero
tspan=[0 50]; % Set up the time span for the intergartion
%% Use the ode45 solver to solve the equations of motion over the required time span
[t,y]=ode45('Q3func',tspan,y0);
% Plot the time history
plot (t,y(:,1)) % x
plot (t,y(:,2)) % y
plot (t,y(:,3)) % theta
%Set the axis range
% axis([0 20 0 1.8]);
% Label the plot
xlabel('Time (s)')
ylabel('Response of Structure')
any help would be HUGELY appricated :) thank you!
  4 Kommentare
Torsten
Torsten am 16 Nov. 2022
What are the equations you are trying to solve in a mathematical notation ? I cannot reconstruct them from your code.
Sophie Scott
Sophie Scott am 16 Nov. 2022
Firstly we are trying to solve the equation for Fleg as a function of time and plotted.
Next we need to solve the x and y components of the Fleg (3 equations of motion have been made, and the matrices have been defined in the code)
Lastly, the maximum amplitudes of x, y and theta (shown in comments as y(1),y(2) and y(3)) using the ode45 solver

Melden Sie sich an, um zu kommentieren.

Antworten (1)

SANKALP DEV
SANKALP DEV am 7 Sep. 2023
Hey Sophie,
I understand that you are encountering an error message stating "Not enough input arguments" while executing your code. The error message you are encountering, suggests that the function Q3func is not receiving the required input arguments. To address this issue, you can make following changes to the code.
In your code, you have defined the function Q3func ‘which expects two input arguments,’ t and y’, but you are not passing these arguments when calling the ode45 solver. To fix this issue, you need to modify the ode45 function call to include the input arguments t and y for the function Q3func like this:
[t, y] = ode45(@Q3func, tspan, y0);
Make sure to include the’@’ symbol before the function name to pass the function handle correctly.
Also, when I was trying to reproduce the issue on my side , got this error:
Dimensions of arrays being concatenated are not consistent.’
To resolve this issue, you need to ensure that the dimensions of zeromatrix2 and ‘-inv(M)*F’ match before concatenating them vertically. In this case, ‘zeromatrix2’ is a 1x3 matrix, and -inv(M)*F is a 3x1 matrix.
To fix this error, you can transpose zeromatrix2 to make it a 3x1 matrix before concatenating it with -inv(M)*F.
To learn more about ‘ode45’ and MATLB function handle, please refer to following MATLAB documentations-
  1. https://www.mathworks.com/help/matlab/function-handles.html
  2. Solve nonstiff differential equations — medium order method - MATLAB ode45 (mathworks.com)
Hope this helps.

Community Treasure Hunt

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

Start Hunting!

Translated by