IF statements together with ODE
2 views (last 30 days)
Show older comments
Hello,
I am fairly new to matlab and have a problem I can't figure out. The following script belongs to a system of a floatating device that is tethered to a motor on the seafloor. The system should describe the dynamics of the floater going from 0 m depth to -1000 m (charging) and from -1000 to 0 m (discharging), when it reaches the surface(0 m) the F_t (the force on the cable) becomes larger than the K (which is the buoyancy minus the weight). However I can't seem to figure out how to work out the if statements for the floater reaching the surface and to then change the F_t and F_d for the system going down( this is charging).
Could someone help me out with this?
Thanks
clear;clc;
%parameters
g = 9.81 ;
rho_s = 7850;
rho_f = 997 ;
r_out = 20 ;%m
r_in = 18;
A = pi*r_out^2;
V_f = (4/3)*pi*r_in^3;
V_s = (4/3)pi(r_out-r_in)^3;
V_tot = (4/3)*pi*r_out^3;
rho_tot= (rho_f*V_f + rho_s*V_s)/V_tot; %kg
Cd = 0.15 ;
m = rho_tot*V_tot;
F_b = rho_f*g*V_tot;
F_z = m*g;
K = F_b - F_z; %constant K
F_T = 6*10^7; %N
%charge: F_d = + & discharge: F_d = -
% : F_T > K & : F_T < K
F_d_charge = rho_f*Cd*A;
F_d_discharge = -rho_f*Cd*A;
if z(t) < 0
F_D = F_d_charge;
F_T = 6e+07;
if zSol(t) == -1000
F_D = F_d_discharge;
F_T = 9.5e+07;
else
zSol(t) > 0
return
end
end
syms v(t) z(t)
A = [(F_D*(abs(v))/(2*m)) 0; 1 0];
B = [K/m - F_T/m; 0];
Y = [v; z];
eq = diff(Y) == A*Y + B;
[vSol(t), zSol(t)] = dsolve(eq);
vSol(t) = simplify(vSol(t));
zSol(t) = simplify(zSol(t));
%Initial conditions
C = Y(0) == [0; 0];
[vSol(t), zSol(t)] = dsolve(eq, C);
%graph
clf
grid on
hold on
title('ODE Dynamics of the system')
subplot(2,1,1)
fplot(vSol)
% fplot(v2Sol)
xlim([0 50])
ylim([0 35])
ylabel('v (m/s)')
title('Velocity')
subplot(2,1,2)
fplot(zSol)
% fplot(z2Sol)
xlim([0 250])
xlabel('t')
ylabel('z (m)')
title('Displacement')
0 Comments
Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!