Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #11422 > unrolled thread
| Started by | JYeom <cygnis@hanmail.net> |
|---|---|
| First post | 2012-08-20 08:16 +0000 |
| Last post | 2012-10-19 06:48 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
How to make fitting code using NDSolve? JYeom <cygnis@hanmail.net> - 2012-08-20 08:16 +0000
Re: How to make fitting code using NDSolve? "Kevin J. McCann" <kjm@KevinMcCann.com> - 2012-08-21 01:39 +0000
Re: How to make fitting code using NDSolve? long.he.dragon@gmail.com - 2012-10-19 06:48 +0000
| From | JYeom <cygnis@hanmail.net> |
|---|---|
| Date | 2012-08-20 08:16 +0000 |
| Subject | How to make fitting code using NDSolve? |
| Message-ID | <k0sroq$jn4$1@smc.vnet.net> |
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?
[toc] | [next] | [standalone]
| From | "Kevin J. McCann" <kjm@KevinMcCann.com> |
|---|---|
| Date | 2012-08-21 01:39 +0000 |
| Message-ID | <k0uoru$n7j$1@smc.vnet.net> |
| In reply to | #11422 |
There are a couple of problems below.One is that you have a number of
subscripted variables that need to be Symbolized first. Also, your call
of model in FindFit has both the variables as inputs (ok), and the
desired output, but the latter is not defined as an output in your
definition of model.
I prefer to roll my own lsq rather than use FindFit, and have included a
notebook under separate email. Hope this helps.
Kevin
On 8/20/2012 4:16 AM, JYeom wrote:
> 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?
>
[toc] | [prev] | [next] | [standalone]
| From | long.he.dragon@gmail.com |
|---|---|
| Date | 2012-10-19 06:48 +0000 |
| Message-ID | <k5qt37$nbr$1@smc.vnet.net> |
| In reply to | #11422 |
Hi Yeom
I am facing some similar problem as yours. Do you have any solution for your original post ?
Thanks for sharing
Long
On Monday, August 20, 2012 2:16:26 AM UTC-6, JYeom wrote:
> 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?
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web