lsqcurvefit not working with coupled ODE Function

I have an assignment where we needed to extract data points from an article, fit to a coupled ODE equation per the article, integrate (I used ODE45), and finally optimize the initial parameters from the ODE with something like lsqcurvefit.
Every other aspect of my program works except the final point. I have been using lsqcurvefit to call the ODE function output in a vector set, but it tells me that it can't "find the function" or there's an issue with my anonymous function calling. I don't believe it is an issue in my vectors (i.e. the ODE model graph outputs a 325 x 3 matrix, my initial parameters are all listed in a column vector and referenced in the ODE, the time vector is a 325 x1, and the experimental parameters are again a 325x3 matrix).
For reference, here is the function-call in the main function:
init_parameters=[ux0_orig;udt_orig;uxl_orig;usd0_orig;ue0_orig;us0_orig;ks_orig;ke_orig;kx_orig]; %set initial parameter guess array
pfit = lsqcurvefit(@(param_vector) optimization_beer_fermentation(param_vector, tspan, y0), init_parameters, t_data, dataexp);
--
My optimization function:
function y_model = optimization_beer_fermentation(param_vector, tspan, y0)
[~, y] = ode45(@(t, y) Beer_fermentation(t, y, param_vector), tspan, y0);
X = y(:, 1) + y(:, 2) + y(:, 3);
S = y(:, 4);
EtOH = y(:, 5);
y_model= [X,S,EtOH];
end
My ODE function:
function dydt=Beer_fermentation(t,y, param_vector)
%ODE function defined in 'A dynamic simulation and Visualisation of Fermentation: Effect of Process Conditions on Beer Quality' Rodman
%this function models the rate of change in a fermentation process and defines the concentration change of active cells, latent cells, dead cells, sugar, and ethanol
% Inputs:
# t (time)
# y (concentration profiles active cells y(1), latent cells y(2), dead cells y(3), sugar y(4), ethanol y(5))
# parameters:
## ux0 max specific growth rate. Arrehenius type.
## usd0 max value that can be reached (or initial condition). Arrehenius type
## ue0= max specific ethenol production, reached (??). Arrehenius type.
## us0= max specific consumption rate of sugar, reached initially. Arrehenius type.
## ks= sugar affinity constant
## ke= ethanol affinity constant
## kx= biomass affinity constant
% Outputs: dydt (differential of the state as computed by the ODE equations y)
dydt=zeros(5,1); %initialize vector
%declare coefficients as global for future curve fitting
%initial condition estimation
S0= 109.056; %initial concentration of sugar (pulled from data)
%define constants in eqns
ux= (param_vector(1)*y(4))/(param_vector(9)+y(5)); %active cell growth rate factor
usd= (param_vector(4)*0.5*S0)/(0.5*S0+y(5)); %dead cell settling
us=(param_vector(6)*y(4))/(param_vector(7)+y(4)); %sugar consumption
ue=(param_vector(5)*y(4))/(param_vector(8)+y(4)); %ethanol production
f=1-(y(5))/(0.5*S0); %inhibition factor
dydt(1)=ux*y(1) - param_vector(2)*y(1)+param_vector(3)*y(2) ;%Active cells, dXadt
dydt(2)=-param_vector(3)*y(2) ;%latent cells, dXldt
dydt(3)=-usd*y(3)+param_vector(2)*y(1) ;%dead cells, dXddt
dydt(4)=-us*y(1) ;%sugar, dSdt
dydt(5)=f*ue*y(1) ;%ethanol, dEtOH
end
Any help is greatly appreciated!

답변 (1개)

Torsten
Torsten 2024년 1월 5일
이동: Torsten 2024년 1월 5일
Use
pfit = lsqcurvefit(@(param_vector,tspan) optimization_beer_fermentation(param_vector, tspan, y0), init_parameters, t_data, dataexp);
instead of
pfit = lsqcurvefit(@(param_vector) optimization_beer_fermentation(param_vector, tspan, y0), init_parameters, t_data, dataexp);

카테고리

질문:

2024년 1월 5일

이동:

2024년 1월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by