Using the force output calculated in one script as an input to mass/spring damper

30 次查看(过去 30 天)
Hi, I'm very much new to Matlab so would appreciate some guidance with a problem I'm having.
Background: I'm trying to build a very simple model of an offshore wind turbine using a spring and damper model. I have a script whose output is a force that varies with time. I also have a function called 'myspring' that solves the position and velocity of a mass on a spring, considering damping and driving force.
I want to use the force I have calculated using my script as the driving force input to 'myspring', but I can't figure out how I can make it work.
Here is what I have. Firstly the 'Morison' script to calculate the force. The content is not important - it could be any force.
% Morison equation force on body
% Define the variables
H = 3.69; % Wave height (m)
A = H/2; % Wave amplitude (m)
Tw = 9.87; % Wave period (s)
omega = (2*pi)/Tw; % Angular frequency (rad/s)
lambda = 128.02; % Wavelength (m)
k = (2*pi)/lambda; % Wavenumber (1/m)
dw = 25; % Water depth (m)
Cm = 2; % Mass coefficient (-)
Cd = 0.7; % Drag coefficient (-)
rho = 1025; % Density of water (kg/m^3)
D = 3; % Diameter of structure (m)
x = 0; % Fix the position at x = 0 for simplicity
n = 100; % Number of time steps
t = linspace(0,6*pi,n); % Define the vector t with n time steps
eta = A*cos(k*x - omega*t); % Create the surface elevation vector with size equal to t
F_M = zeros(1,n); % Initiate an inertia force vector with same dimension as t
F_D = zeros(1,n); % Initiate a drag force vector with same dimension as t
F = zeros(1,n); % Initiate a total force vector with same dimension as t
fun_inertia = @(z)cosh(k*(z+dw)); % Define the inertia function to be integrated
fun_drag = @(z)(cosh(k*(z+dw)).*abs(cosh(k*(z+dw)))); % Define the drag function to be integrated
for i = 1:n
F_D(i) = abs(((H*pi)/Tw) * (1/sinh(k*dw)) * cos(k*x - omega*t(i))) * ((H*pi)/Tw) * (1/sinh(k*dw)) * cos(k*x - omega*t(i)) * integral(fun_drag,-dw,eta(i));
F_M(i) = (Cm*rho*pi*(D^2)/4) * ((2*H*pi^2)/(Tw^2)) * (1/(sin(k*dw))) * sin(k*x - omega*t(i)) * integral(fun_inertia,-dw,eta(i));
F(i) = F_D(i) + F_M(i);
end
and now 'myspring.m':
function pdot = myspring(t,p,c,k,m)
w = sqrt(k/m);
g = sin(t); % This is the forcing function
pdot = zeros(size(p));
pdot(1) = p(2);
pdot(2) = g - c*p(2) - (w^2)*p(1);
end
where k = spring stiffness, c = damping, m = mass. These values are specified before running ode45 with 'myspring'.
So in summary, is there a way I can replace my 'g = sin(t)' driving function which I have written into 'myspring' with the force calculated in my 'Morison' script? Any support is appreciated.

回答(2 个)

Thorsten
Thorsten 2016-7-4
编辑:Thorsten 2016-7-4
Turn your script into a function by adding these lines on top of your script
function F = morison(t)
if nargin == 0 % define default argument
t = linspace(0,6*pi,n); % Define the vector t with n time steps
end
and remove from the body of the function
t = linspace(0,6*pi,n);
You can then use the function "morison" as follows:
g = morison(t);
Just like a build-in function like sin.
  4 个评论
Thorsten
Thorsten 2016-7-5
When g is a vector, g - c*p(2) - (w^2)*p(1); is a vector. You cannot assign a vector to a single variable
pdot(2)

请先登录,再进行评论。


Ondrej Piroh
Ondrej Piroh 2022-4-6
I would like to ask if this equation is applicable for deep waves and if the ratio between D / lamba> 0.2 ?

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by