Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10373 > unrolled thread

please help using NDSolve and FindFit

Started byLee <lee787@comcast.net>
First post2012-06-07 09:20 +0000
Last post2012-06-08 07:36 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  please help using NDSolve and FindFit Lee <lee787@comcast.net> - 2012-06-07 09:20 +0000
    Re: please help using NDSolve and FindFit Robert Miller <robertelmiller@gmail.com> - 2012-06-08 07:36 +0000

#10373 — please help using NDSolve and FindFit

FromLee <lee787@comcast.net>
Date2012-06-07 09:20 +0000
Subjectplease help using NDSolve and FindFit
Message-ID<jqprpc$2dv$1@smc.vnet.net>
As reading tutorials by Mathew Smith, I am trying to fit six (t,f) data points in range t=[0,5] using a conditional differential equation.

texp = {0.5, 1.1, 1.5, 2.1, 2.3, 3.1};
fexp = {6.2, 8.1, 8.8, 8.3, 6.8, 2.9};
data = Transpose[{texp, fexp}];
model[p_?NumberQ, q_?NumberQ] := First[f /. NDSolve[{f'[t] == If[t < p, 10 - f[t], -f[t]], f[0] == q}, f, {t, 0, 5}]];
fit = FindFit[data, model, {{p, 2}, {q, 4}}, f];

Mathematica gave the following error message:

FindFit::nrlnum: The function value {-6.2+model, -8.1+model, -8.8+model, -8.3+model, -6.8+model, -2.9+model} is not a list of real numbers with dimensions {6} at {p,q} = {2.,4.}.

The answer should have been around:

{p->1,9962, q->3.93581}

Does anyone know how to correct it?

[toc] | [next] | [standalone]


#10393

FromRobert Miller <robertelmiller@gmail.com>
Date2012-06-08 07:36 +0000
Message-ID<jqsa2l$de0$1@smc.vnet.net>
In reply to#10373
Try
fit = FindFit[data, model[p, q][f], {{p, 2}, {q, 4}}, f]
I get
{p -> 1.99877, q -> 3.99766}
along with a FindFit::sszero message

On Thursday, June 7, 2012 2:20:44 AM UTC-7, Lee wrote:
> As reading tutorials by Mathew Smith, I am trying to fit six (t,f) data points in range t=[0,5] using a conditional differential equation.
> 
> texp = {0.5, 1.1, 1.5, 2.1, 2.3, 3.1};
> fexp = {6.2, 8.1, 8.8, 8.3, 6.8, 2.9};
> data = Transpose[{texp, fexp}];
> model[p_?NumberQ, q_?NumberQ] := First[f /. NDSolve[{f'[t] == If[t < p, 10 - f[t], -f[t]], f[0] == q}, f, {t, 0, 5}]];
> fit = FindFit[data, model, {{p, 2}, {q, 4}}, f];
> 
> Mathematica gave the following error message:
> 
> FindFit::nrlnum: The function value {-6.2+model, -8.1+model, -8.8+model, -8.3+model, -6.8+model, -2.9+model} is not a list of real numbers with dimensions {6} at {p,q} = {2.,4.}.
> 
> The answer should have been around:
> 
> {p->1,9962, q->3.93581}
> 
> Does anyone know how to correct it?

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web