Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: How to make fitting code using NDSolve?
Replies: 2   Last Post: Oct 19, 2012 2:48 AM

 Messages: [ Previous | Next ]
 JYeom Posts: 1 Registered: 8/20/12
How to make fitting code using NDSolve?
Posted: Aug 20, 2012 4:16 AM

Hello,
I am trying to fit some basic data to a partial differential equation- here are the data points:

data = {
{2.113, 2.915*^-7}, {2.256, 2.758*^-7}, {2.303, 2.567*^-7}, {2.493,
2.343*^-7}, {2.635, 2.085*^-7}, {2.825, 1.838*^-7}, {3.015,
1.614*^-7}, {3.205, 1.412*^-7}, {3.538, 1.199*^-7}, {3.775,
1.03*^-7}, {4.108, 8.173*^-8}, {4.487, 6.266*^-8}, {4.915,
4.695*^-8}, {5.295, 3.349*^-8}, {5.912, 2.34*^-8}, {6.672,
1.554*^-8}, {7.527, 7.692*^-9}, {8.524, 5.448*^-9}, {9.426,
4.326*^-9}, {10.23, 3.205*^-9}, {10.99,
2.083*^-9}, {11.99, -1.608*^-10}
}

And there are four parameters to fit in our fitting equation:

model[ka_?NumberQ, kr_?NumberQ, kd_?NumberQ,
kb_?NumberQ] := (model[ka, kr, kd, kb] =
First[Subscript[Dye, 0] /. NDSolve[{
Derivative[1][Subscript[Dye, 0]][
t] ==\[VeryThinSpace]-ka Subscript[Dye, 0][t] +
kr Subscript[Dyes, 0][t], Subscript[Dye, 0][0] == 1.22 10^-6,
Derivative[1][Subscript[Dye, 1]][
t] == -ka Subscript[Dye, 1][t] + kr Subscript[Dyes, 1][t],
Subscript[Dye, 1][0] == 0,

Derivative[1][Subscript[Dyes, 0]][t] ==
ka Subscript[Dye, 0][t] - kr Subscript[Dyes, 0][t] -
kd Subscript[CI, 0][t] Subscript[Dyes, 0][t] -
kd /2 * Subscript[CI, 1][t] Subscript[Dyes, 1][t],
Subscript[Dyes, 0][0] == 0,
Derivative[1][Subscript[Dyes, 1]][t] ==
ka Subscript[Dye, 1][t] -
kd Subscript[CI, 1][t] Subscript[Dyes, 0][t] -
kr Subscript[Dyes, 1][t] -
kd Subscript[CI, 0][t] Subscript[Dyes, 1][t],
Subscript[Dyes, 1][0] == 0,

Derivative[1][Subscript[CI, 0]][
t] == -kd Subscript[CI, 0][t] Subscript[Dyes, 0][t] -
kd/2* Subscript[CI, 1][t] Subscript[Dyes, 1][t] -
kb Subscript[CI, 0][t] Subscript[HDye, 0][t] -
kb/2* Subscript[CI, 1][t] Subscript[HDye, 1][t],
Subscript[CI, 0][0] == 3.18 10^-3,
Derivative[1][Subscript[CI, 1]][
t] == -kd Subscript[CI, 1][t] Subscript[Dyes, 0][t] -
kd/2* Subscript[CI, 0][t] Subscript[Dyes, 1][t] -
kb Subscript[CI, 1][t] Subscript[HDye, 0][t] -
kb/2*Subscript[CI, 0][t] Subscript[HDye, 1][t],
Subscript[CI, 1][0] == 0,

Derivative[1][Subscript[HDye, 0]][t] ==
kd Subscript[CI, 0][t] Subscript[Dyes, 0][t] +
kd/2* Subscript[CI, 1][t] Subscript[Dyes, 1][t] -
kb Subscript[CI, 0][t] Subscript[HDye, 0][t] -
kb /2* Subscript[CI, 1][t] Subscript[HDye, 1][t],
Subscript[HDye, 0][0] == 0,
Derivative[1][Subscript[HDye, 1]][t] ==
kd Subscript[CI, 1][t] Subscript[Dyes, 0][t] +
kd Subscript[CI, 0][t] Subscript[Dyes, 1][t] -
kb Subscript[CI, 1][t] Subscript[HDye, 0][t] -
kb Subscript[CI, 0][t] Subscript[HDye, 1][t],
Subscript[HDye, 1][0] == 0
}, {Subscript[Dye, 0][t], Subscript[Dyes, 0][t],
Subscript[CI, 0][t], Subscript[HDye, 0][t],
Subscript[Dye, 1][t], Subscript[Dyes, 1][t],
Subscript[CI, 1][t], Subscript[HDye, 1][t]}, {t, 0, 12}]])

In the NDSolve, what we want to fit is Dye0[t]. So we wrote code for fitting using FindFit:

fit = FindFit[data,
model[ ka, kr, kd, kb][Subscript[Dye,
0]], {{ka, 10^(-4)}, {kr, 10^(-4)}, {kd, 500}, {kb, 500}},
Subscript[Dye, 0]]

However, we encountered the error message like this:

FindFit::nrlnum: "The function value {-2.915*10^-7+Subscript[Dye, 0][2.113],-2.758*10^-7+Subscript[Dye, 0][2.256],-2.567*10^-7+Subscript[Dye, 0][2.303],<<16>>,-3.205*10^-9+Subscript[Dye, 0][10.23],-2.083*10^-9+Subscript[Dye,0][10.99],1.608*10^-10+Subscript[Dye, 0][11.99]} is not a list of real numbers with dimensions {22} at {ka,kr,kd,kb} = {0.0001,0.0001,500.,500.}."

The desirable solution for parameter is around ka= 0.67, kr = 10^(-3), kd=1600, kb=1600.

Does anyone know what I am doing wrong?

Date Subject Author
8/20/12 JYeom
8/20/12 Kevin J. McCann
10/19/12 long.he.dragon@gmail.com