MATLAB Answers

Parameters estimation for a System of differential equations, gives error

18 views (last 30 days)
Miguel Figueroa
Miguel Figueroa on 10 Dec 2019
Edited: Miguel Figueroa on 10 Dec 2019
Hello everybody, I'm a student really struggling with this college assignment. I'm trying to estimate the parameters needed to fit my experimental data to a model of two differential equations of the form:
I have a set of experimental data for my measured value y, [FeOOH] and [O_3], and obviously time while x is just a variable that came up during the modelling and doesn't have experimental data. However, it's solvable at everypoint after evaluating all the experimental data. I found several similar examples in here, such as:
Following the advice of @Star Strider, that answered both problems, curiously. My adjustable parameters are those k's you see and the alphabetical letters like a,b,c,f,g,h, etc. I have 84 experimental values for each variable. I literally copied my equations in the sintax he used for the first link and I get the following error:
I'm attaching my code, please run it and see the error, it says the matrix Index exceeds dimensions for the differential equation of dx/dt. I have a hunch that it might be about the number of parameters I'm using is not the number of parameters I'm generating for my initial guess, I considered 18 but I'm gonna recount. If anyone finds it possible to run please comment!


Star Strider
Star Strider on 10 Dec 2019
I cannot follow what you are doing.
It appears that you are fitting 2 differential equations to a matrix of 3 variables. That is just not going to work. You can only fit 2 columns of ‘c’ to your two differential equations.
There are several discontinuities within ‘t’ (that re-starts to 0 within the vector), and columns 2 and 3 of ‘c’. The MATLAB ODE solvers cannot deal effectively with these discontinuities. Also, the discontinuities in ‘t’ do not match the discontinuities in ‘c’.
Additionally, you are apparently fitting 18 parameters. The segments of your data between the discontinuities do not contain enough data to allow that. There must be at least 19 data sets (‘t’ and rows of ‘c’) for that to provide unambiguous parameter estimates.
Please understand that you cannot just take existing code and use it with incompatible data and expect any sort of a correct result. It is necessary to understand the code and the characteristics of the MATLAB ODE solvers in order to use them effectrively.
I cannot help you with your code and data as they exist.
Miguel Figueroa
Miguel Figueroa on 10 Dec 2019
Hello, sir Star Stride. Thank you very much for your input. I would like to clarify some things in hopes that we can come up with an answer. First, of the two differential equations I'm only trying to fit one 'c', which is c(2), which represents concentracion of a compound called DCF. The first differential equation for c(1) is a just function that gives me a value of a factor called [OH] that is present in the ODE for DCF (c(2)), but it's not something I want to fit, because it's not physically possible to measure it. So, following your work for the Monoid kinetic problem, you did something similar: two ODE's in which you only have real data for the second variable and use the data to find a value for y(1) that is later used for y(2). I tried to replicate that idea here. The other two ODE's (dcdt(3) and dcdt(4)) were just me trying to follow the same template of the Igor_Moura code, since he had to fit data for 4 variables, but since I only had to do it for one, I made them equal to 0.
About the discontinuities, I made 9 experiments, so I would have 10 data sets, one for time and 8 sets of c(2).Does that mean I can only fit 9 parameters and not more? The other two variables (FeOOH) and (O_3) are also independent variables that affect c(2), but they were kept constant for each data set, albeit with different values. I didn't know how to best represent that. So each data set looks like this:
t: from 0 to 20 minutes.
DCF: from y0 to final value at 20 minutes.
FeOOH: Constant value, but different for each experiment.
O_3: Constant value, but different for each experiment.
How should I introduce those 10 data sets to my function, then? In order for the lsqcurvefit to go through each of them. I see it's not alright to just mash them all together in two columns.
And finally, about the constants, I also made a slip up there, after counting thoroughly, I noticed I used an old expression that was made up of 18 constants, but now I've reduced to 14, I will try to reduce it even further
%theta(1) = k_o3; theta(2) = k_oh; theta(3) = k_18; theta(4) = k_9;
%theta(5) = k_-9; theta(6) = k_4: theta(7) = k_6; theta(8) = b; theta(9) =
%f; theta(10) = j; theta(11) = a; theta(12) = e; theta(13) = g; theta(14) = h
I'm gonna try to fix it up as much as possible and link it here. Maybe I can make it work. I was desperate and your solutions were so similar to mine I thought it would just work. I'm sorry.
Edit: So I've just noticed I'm an idiot. I don't have 14 constants. I only have 8, but during my derivation of the model they were so scary looking that I transformed to alphabetical letters and ended up with double that. Here's what each letter there meant, so I'm gonna fix that and see if it works now:
Sin título.png
Miguel Figueroa
Miguel Figueroa on 10 Dec 2019
I've come back with an update. I have tried to find my own way of solving the problem and tried using the function fminsearch. I also tried to fit just the first set of parameters, this one:
t = [ 0 4 8 12 16 20]
DCF = [ 0.054768223996110 0.052379215797507 0.048236017126572 0.018099058578819 0.006820913867391 0.002853303078191]
FeOOH = [ 9.003939223410242 9.003939223410242 9.003939223410242 9.003939223410242 9.003939223410242 9.003939223410242]
O_3 = [ 0.066666666666667 0.066666666666667 0.066666666666667 0.066666666666667 0.066666666666667 0.066666666666667];
And although the script runs without erros and gives me a sum of squared of errors of 0.014 approx. I get the following plot:
My function drops down at t= 0 and then follows a straight line. How is this possible, if the parameters I used give an error of just 0.014? Attached is the script.

Sign in to comment.

Answers (0)

Sign in to answer this question.