Dear Star Strider,
I appreciate your detailed explanation. I was trying to use your script to reproduce my case. However, I found my data can not be read when the 'X' is within the 'function'. Therefore, I can not check the potential problem based on your example. My data and code have been attached.
The error is:
Unrecognized function or variable 'Surge'.
Error in yu_gao (line 44)
X = [Surge PlatfromPitch VarName17 Heave SurgeVelocity PlatformPitchsVelocity VarName11 HeaveVelocity];
Best wishes,
Yu
function yu_gao
function kineticsmodel(un,t)
X0 = [0;10;10;0;0;0;0;0]; % [x10;x20;x30;x40; dx1dt0;dx2dt0;dx3dt0;dx4dt0]
[t, Xv] = ode45(@odefn,t,X0);
function dxdt = odefn(t,X)
x = X(1:4);
xdot = X(5:8);
M = [m mt*ht Iac 0;...
mt*ht It 0 0;...
Iac 0 Ip+mp*hp^2 0;...
0 0 0 m];
A = [ma 0 -mp*hp 0;...
0 mt*ht^2 0 0;...
-mp*hp 0 Ia 0;...
0 0 0 mh];
C = [un(4) 0 un(7) 0;...
0 un(5) -un(5) 0;...
un(7) -un(5) un(5)+un(6) 0;...
0 0 0 ch];
K = [un(1) 0 -un(1)*z 0;...
0 un(2)-mt*ht -un(2) 0;...
-un(1)*z -un(2) un(3)+un(1)*z^2+un(2)+mp*g*hp 0;...
0 0 0 kh];
xddot = (M+A)\(-K*x-C*xdot);
dXdt = [xdot xddot];
end
X=Xv;
end
tspan = 0:0.1:675;
X0 = [0;10;10;0;0;0;0;0];
X = [Surge PlatfromPitch VarName17 Heave SurgeVelocity PlatformPitchsVelocity VarName11 HeaveVelocity];
z = 14;
ht = 56.50;
hp = 14.94;
height_t = 129.13;
g = 9.81;
m = 20093000; % total mass
mp = 17839000; % platform mass
It = 6.561*10^9;
Ip = 1.251*10^10;
mt = 2254000; % tower+RNA mass
ma = 9.64*10^6; % Added mass for platform surge
mh = 2.480*10^7; % Added mass for platform heave
Ia = 1.16*10^10; % Added mass for platform pitch
Iac = -1.01*10^8;
ch = 1.3*10^5;
kh = 4.470*10^6;
un0 = [7.964*10^3 1.5944*10^10 4.453*10^6 9.225*10^5 6.9515*10^7 1.676*10^9 -8.918*10^6];
[un,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@kineticsmodel,un0,t,X);
fprintf(1,'\tRate Constants:\n')
for k1 = 1:length(theta)
fprintf(1, '\t\tTheta(%d) = %8.5f\n', k1, un(k1))
end
tv = linspace(min(tspan), max(tspan));
unfit = kineticsmodel(un, tv);
figure(1)
plot(t, c, 'p')
hold on
hlp = plot(tv, unfit);
hold off
grid
xlabel('Time')
ylabel('Concentration')
legend(hlp, 'un_1(t)', 'un_2(t)', 'un_3(t)', 'un_4(t)', 'un_5(t)','un_6(t)','un_7(t)','Location','N')
end