Use of fmincon with objective function as m-file
Mostra commenti meno recenti
I am finding parameters for a model. I thought the best thing was to define the objective function that I wiah to minimise as
function y=objective_fn(V_exp,V_calc,t)
%This is the objective function
N=length(t); %gets length of vectors
%define the weight of the objective function to concentrate on a particular
%feature
w=ones(1,N);
y=trapz(t,(V_exp.*w-V_calc).^2);
So the minimum is where the V_calc is very close to V_exp, which is experimental data we have. Now V_calc is given by:
function V=volt(O_plus,O_minus,X,L_a,L_c,I_app,t)
%Compute the lithium concentration in each of the
r=linspace(0,1,100);
D_a=X(1);
D_c=X(2);
u_0_a=X(3);
u_0_c=X(4);
k_a=X(5);
k_c=X(6);
alpha_a=X(7);
alpha_c=X(8);
c_a_max=X(7);
c_c_max=X(8);
c_a_full=spherical_fd(u_0_a,I_app/L_a,D_a,D_a,r,t);
c_a=c_a_full(:,end);
c_c_full=spherical_fd(u_0_c,I_app/L_c,D_c,D_c,r,t);
c_c=c_c_full(:,end);
%Compute Voltage
V=O_plus(c_c)+eta_SPM(c_c,k_c,c_c_max,T,-alpha_c*I_app/L_c)-(O_minus(c_a)+eta_SPM(c_a,k_a,c_a_max,T,alpha_a*I_app/L_a));
To use this objective function, would I need to incorporate them into one big function? The parameters I wish to optimise are contained in the vector X, O_plus/O_minus are fixed rational functions of c_c, and c_a, t is time, I_app, L_a and L_c are constant. I'm a bit confused how to fit these functions into fmincon.
Risposta accettata
Più risposte (1)
fun=@(X) objective_fn(V_exp, volt(O_plus,O_minus,X,L_a,L_c,I_app,t) ,t); %anonymous function
x=fmincon(fun,x0,...)
Categorie
Scopri di più su Nonlinear Optimization in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!