optimising a parameter not directly involved in the objective function to be minimised
Afficher commentaires plus anciens
someone kindly help me write a code to optimise h using fminsearch such that SSE is minimised. h is is not directly invloved in solving for SSE but is involved in the first differential equation whose output, 'L' is used in the subquest non-differential equations.
I am trying to replicate a publication in which it's mentioned that, 'equation 1 is a 1st order ODE solved by 4th order Runge-kutta solver which facilitates simultaneous solution of equation 2-4 at each time step'. I wonder how to simulataneously solve the differential equation and non-differential equation using ODE45. At the moment am only solving for equation 1 using the ODE45 and then solve for the non-differential equations.
Thank you.
%constants; KA, KV, p, D, Cs, mo, Ni and V
% Cb_exp is a column vector
dLdt = -(KA / (3 * p * KV)) * (D / h) .* (Cs - Cb_exp); %equation 1
mi_j = p * KV *((L).^3)*Ni; % Equation 2
Cb_cal = (mo - mi_j) / V; % Equation 3
S = KA * (L).^2 * Ni / V; % Equation 4
SSE= sum(Cb_cal-Cb_exp)^2
2 commentaires
Torsten
le 29 Fév 2024
As far as I understand your equations, mi_j, Cb_cal and S can be directly computed once you know L. So what's the problem ? You don't need to "solve" for them with the integrator you use.
Réponses (1)
t_exp = ...;
Cb_exp = ...; % experimental data
KA =...;
KV =...;
p =...;
D =...;
Cs =...;
mo =...;
Ni =...;
V =...; % constants
h0 = ...; % Guess value for h
h = lsqnonlin(@(h)fun(h,t_exp,Cb_exp,KA, KV, p, D, Cs, mo, Ni,V),h0)
function res = fun(h,t_exp,Cb_exp,KA, KV, p, D, Cs, mo, Ni,V)
tspan = t_exp; % Assumes t_exp starts with t = 0
L0 = ...; % Initial value for L at t=0
fun_ode = @(t,L) -(KA / (3 * p * KV)) * (D / h) * (Cs - interp1(t_exp,Cb_exp,t));
[~,L] = ode45(@fun_ode,tspan,L0);
mi_j = p * KV * L.^3 * Ni;
Cb_cal = (mo - mi_j) / V;
res = Cb_cal - Cb_exp;
end
2 commentaires
[~,L] = ode45(fun_ode,tspan,L0);
res = 1e16*(Cb_cal - Cb_exp);
instead of
[~,L] = ode45(@fun_ode,tspan,L0);
res = Cb_cal - Cb_exp;
Catégories
En savoir plus sur Mathematics and Optimization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!