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


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

Fittings 2 sets of equations and 2 data sets with nonlinearmodelfit

Started byJamesE <haywanlar@excite.com>
First post2011-09-26 08:17 +0000
Last post2011-09-27 00:09 +0000
Articles 2 — 2 participants

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


Contents

  Fittings 2 sets of equations and 2 data sets with nonlinearmodelfit JamesE <haywanlar@excite.com> - 2011-09-26 08:17 +0000
    Re: Fittings 2 sets of equations and 2 data sets with nonlinearmodelfit Ray Koopman <koopman@sfu.ca> - 2011-09-27 00:09 +0000

#5216 — Fittings 2 sets of equations and 2 data sets with nonlinearmodelfit

FromJamesE <haywanlar@excite.com>
Date2011-09-26 08:17 +0000
SubjectFittings 2 sets of equations and 2 data sets with nonlinearmodelfit
Message-ID<j5pcf8$8h2$1@smc.vnet.net>
Hi,

My names is James Ellison; and I have 2 nonlinear equations of the type:

y[1]=x+a*x[1]^2+b*x[1]^3 and y[2]=a*x[2]^3+b*x[2]^5 with the real valued parameters a and b for both equations.

I further have 2 data sets 

data[1] for y[1] and 
data[2] for y[2]
 
I can use NonlinearModelFit in order to fit each data[i] set to its function y[i] and get good fits. But the parameters a and b should be the same.

How can I create a simple code with Mathematica, so that I can do a simultaneous fit resulting in the parameters a and b to be the same.

I am a Mathematica beginner and would be pleased, if someone could answer my question for beginners.

Best regards, James





> In[1]:= data = {{1., 0.75}, {2., 0.89}, {3., 0.42}, {4., 0.99}, {5.,0.84}, {6., 0.34}, {7., 0.83}, {8., 0.93}, {9., 0.76}, {10.,0.11}};
> nlm = NonlinearModelFit[data, {Exp[a + b x^2], b< -1/2}, {{a, 0}, {b, -1}}, x]
>
> In[2]:= nlm[{"ANOVATable", "ParameterConfidenceIntervalTable"}]

[toc] | [next] | [standalone]


#5243

FromRay Koopman <koopman@sfu.ca>
Date2011-09-27 00:09 +0000
Message-ID<j5r47d$ic6$1@smc.vnet.net>
In reply to#5216
On Sep 26, 1:17 am, JamesE <haywan...@excite.com> wrote:
> Hi,
>
> My names is James Ellison; and I have 2 nonlinear equations of the
> type:
>
> y[1]=x+a*x[1]^2+b*x[1]^3 and y[2]=a*x[2]^3+b*x[2]^5 with the real
> valued parameters a and b for both equations.
>
> I further have 2 data sets
>
> data[1] for y[1] and
> data[2] for y[2]
>
> I can use NonlinearModelFit in order to fit each data[i] set to
> its function y[i] and get good fits. But the parameters a and b
> should be the same.
>
> How can I create a simple code with Mathematica, so that I can do
> a simultaneous fit resulting in the parameters a and b to be the
> same.
>
> I am a Mathematica beginner and would be pleased, if someone could
> answer my question for beginners.
>
> Best regards, James

Although your models are nonlinear in x they are linear in the
unknown parameters, and it is the latter that matters here.

Write your model as w = a*u + b*v, where {u, v, w} =
{x^2, x^3, y-x} for data[1] and {x^3, x^5, y} for data[2].

If data[1] and data[2] contain {x,y} pairs then

Join[{#1^2, #1^3, #2-#1}& @@@ data[1],
     {#1^3, #1^5, #2   }& @@@ data[2]}]

will give you a data matrix that can be input to LinearModelFit.
Be sure to specify IncludeConstantBasis->False.

[toc] | [prev] | [standalone]


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


csiph-web