filename = 'Inputs_Force.xlsx';
data = readtable(filename);
use_data=table2cell(data(:,1:6));
use_data=cell2mat(use_data);
Waveforce = use_data(:,2);
Wavemoment =use_data(:,3);
Windforce = use_data(:,5);
Windmoment = use_data(:,6);
subplot(3,1,2), plot(tspan, Windforce), xlabel('time/s'),ylabel('WindForce/N');
subplot(3,1,1), plot(tspan, Waveforce), xlabel('time/s'),ylabel('WaveForce/N');
subplot(3,1,3), plot(tspan, Wavemoment), xlabel('time/s'),ylabel('WaveMoment/N.m')
mu = 0.0084*z_T^3-1.077*z_T^2-171.5*z_T+2.96e04;
EI = 1.905e06*z_T^3-2.47e08*z_T^2-5.208e10*z_T+6.851e12;
Phi_TA = 0.9414*(z_T/H_T)^2+0.3468*(z_T/H_T)^3-1.073*(z_T/H_T)^4+1.3139*(z_T/H_T)^5-0.5289*(z_T/H_T)^6;
fun1 = mu*Phi_TA^2; m_TA = double(int(fun1,z_T,0,H_T));
fun2 = mu*Phi_TA; m_1 = double(int(fun2,z_T,0,H_T));
fun3 = mu*(z_T)*Phi_TA; m_2 = double(int(fun3,z_T,0,H_T));
fun4 = mu*(z_T); m_3 = double(int(fun4,z_T,0,H_T));
fun5 = mu*(z_T)^2; m_4 = double(int(fun5,z_T,0,H_T));
D2y = diff(Phi_TA,z_T,2); Dy = diff(Phi_TA,z_T,1);
fun6 = EI*D2y^2; f1 = int(fun6,0,H_T);
fun7 = mu; f2 = int(fun7,z_T,H_T);
fun8 = g*(m_N+f2)*Dy^2; f3 = int(fun8,0,H_T);
M = [m_N+m_TA m_N+m_1 m_N*h_R+m_2;
m_N+m_1 m_N+m_p+m_T (m_N*h_R-m_p*h_p+m_3+m_T*h_T);
m_N*h_R+m_2 (m_N*h_R-m_p*h_p+m_3) m_N*h_R^2+I_p+m_4];
C = [2*xi_TA*sqrt(m_TA*k_TA) 0 0;
K = [k_TA 0 -(m_N+m_T)*g;
-(m_N+m_T)*g 0 -(m_N*h_R+m_3-m_p*h_p)*g];
0 k_mooringS k_mooringSP;
0 k_mooringSP k_mooringP];
options = odeset('RelTol',1e-10,'AbsTol',1e-10);
[t,X] = ode45(@(t,X) reducedmodel(z,h_R,tspan,t,X,M,M_add,C,C_add,K,K_add,K_mooring,F_wave,M_wave,F_aero,M_aero),tspan,X0,options);
PtfmPitch_deg = X(:,3)*180/pi;
subplot(3,1,1), plot(t,X(:,1)),grid, xlabel('time/ s'), ylabel('TTDspFA/ m')
subplot(3,1,2), plot(t,X(:,2)),grid, xlabel('time/ s'), ylabel('surge/ m')
subplot(3,1,3), plot(t,PtfmPitch_deg),grid, xlabel('time/ s'), ylabel('platform pitch/ deg')
function dXdt = reducedmodel(z,h_R,tspan,t,X,M,M_add,C,C_add,K,K_add,K_mooring,F_wave,M_wave,F_aero,M_aero)
F1 = -coe*xdot(2)*abs(xdot(2));
F2 = -coe1*xdot(3)*abs(xdot(3));
F3 = interp1(tspan, F_wave, t,'spline');
F4 = interp1(tspan, M_wave, 'spline');
F5 = interp1(tspan, F_aero, 'spline');
F6 = interp1(tspan, F_aero*h_R, 'spline');
ex_F = [ex_F, F_external];
xddot = (M+M_add)\(F+F_external-(K+K_add+K_mooring)*x-(C+C_add)*xdot);