how to minimize a parameter

Hi, mi programm is this one
function theoretical1
clc;
clear all;
close all;
tau1=147;
k0=[150000 1.5 1.5 1.5];
nu=[-1; -5 ;-6]; % stoichiometrical matrix of coefficients
C01 = [0.00005 0.001 0.05]; % initial concentratio of measure j
[time1,C1]= ode45(@myode1,[0 tau1],C01);
function dC1dt=myode1(t,C)
R1=k0(1)*C(1)^k0(2)*C(2)^k0(3)*C(3)^k0(4);
r1=nu*R1;
dC1dt=r1;
end
%Volume
V=0.5;
%species A B and C refer to KIO3 KI and H
%Test one
load ('prova1.mat','seconds','absorbance')
csi1_1=0.2276*absorbance/1000; %in mol/L (M)
sec_1=seconds;
%Initial Concentrations
C0_1=[0.00005 0.001 0.05]; %species A,B and C
C0_A_1=C0_1(1); %conc OF IO3- in mol/L
C0_B_1=C0_1(2); %conc OF I- in mol/L
C0_C_1=C0_1(3); %conc OF H+ in mol/L
%Concentration in time
%from excel plot we know that there is a correlation between absorbance and
%the concentration of I2 that follows a linear rule as follows: C=0.081*A
C_A_1=C0_A_1-csi1_1;
CI2_1=absorbance*0.081/1000;
csi2_1=3*csi1_1-CI2_1; %mol/L
C_B_1=C0_B_1-5*csi1_1-csi2_1;
C_C_1=C0_C_1-6*csi1_1;
C_exp_1=[C_A_1 C_B_1 C_C_1];
err1=[C1(2)-C_A_1 C1(3)-C_B_1 C1(4)-C_C_1];
N1=norm(err1);
end
I have some experimental values of concentration C given and I have to hypothize the values of of the vector k0 in order to calculate a theoretical concentration. What I would like to do now is to minimize the norm N1 by optimizing the values of k0. I know that there are some functions as fminsearch but I really don't know how to use them. Can someone help me with this? Thank you

답변 (2개)

Alan Weiss
Alan Weiss 2016년 2월 24일

0 개 추천

Alan Weiss
MATLAB mathematical toolbox documentation

댓글 수: 2

Gisela
Gisela 2016년 2월 24일
But if my parameters are within an ode, where do I insert this function? Because reading your link I define the function in Fittedcurve, yet I cannot defined the function that way.
Alan Weiss
Alan Weiss 2016년 2월 24일
Perhaps this example will help. It uses patternsearch instead of fmincon, but fmincon works, too, especially if you set larger-than-default finite differences.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

댓글을 달려면 로그인하십시오.

Star Strider
Star Strider 2016년 2월 24일

0 개 추천

I cannot follow your code, but if you want to fit data using an ODE in your objective function, see: Monod kinetics and curve fitting.

댓글 수: 4

Gisela
Gisela 2016년 2월 25일
I'm also having a hard time following the link you posted. My problem is basically this: i have vector C_exp_1 which is something I know. Now they tell me the reaction rate is k1C1^a*C2^b*C3^c. Knowing the initial concentration I have to find the values of k1,a,b,c in order to minimize the error between the values present in my vector C_exp_1 and the values of C1, C2 and C3 calculated through the ODE
Torsten
Torsten 2016년 2월 25일
편집: Torsten 2016년 2월 25일
Set
B0 = [k1 a b c]
Time = Vector of the times when the measurements were performed
(threefold repeated) [0 0 0 t1 t1 t1 t2 t2 t2 ... tn tn tn]
Sdata = Vector of concentrations at the time instants for the three components
[C01 C02 C03 C11 C12 C13 C21 C22 C23 ... Cn1 Cn2 Cn3]
x0 = Vector of initial concentrations [C01 C02 C03]
t in the call to ODE45 = [0 t1 t2 ... tn]
S = [Sv(1,1) Sv(1,2) Sv(1,3) Sv(2,1) Sv(2,2) Sv(2,3) ... Sv(n+1,1) Sv(n+1,2) Sv(n+1,3)]
Best wishes
Torsten.
Gisela
Gisela 2016년 2월 25일
To Torsten I'm assuming that S is the error I was talking about. But how do I minimize it? Or the way in which you set it is already minimized?
Torsten
Torsten 2016년 2월 25일
Yes, lsqcurvefit automatically forms the sum of squared differences between S and Sdata.
Best wishes
Torsten.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

태그

질문:

2016년 2월 24일

댓글:

2016년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by