Message Boards Message Boards

0
|
7626 Views
|
6 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Obtain a multiple variable Nonlinear fit using NonlinearModelFit?

Posted 6 years ago

I am trying to make a Nonlinear fit of the following efvc functional, where I want to vary parameters from alpha and gamma equations. I kept trying the way I thought it would work, but I always get an the error FindFit::fitd: "First argument in FindFit is not a list or a rectangular array".

Clear[n, m, u, w, bint, beta, g, dg, bb, dbb, gama, dgama, fvc, defvc]
    {beta[0.] = 2, beta[Infinity] = 1}

    {2, 1}

    beta

    bint[u_?NumericQ] := If[u != 0,
      NIntegrate[BesselJ[0, x] BesselJ[1, x]/(x + x Exp[u 
              x/2]), {x, 0, Infinity}]]
    beta[u_?NumericQ] := x /. FindRoot[(x/Pi) Sin[Pi/x] == 2 bint[u], {x, 1, 0, 2}]


    efvc 

    bb[n_, m_, u_] := beta[u]^alpha[n, m, u]

    alpha[n_, m_, u_] := ((n^2 - m^2)/n^(A))^CubeRoot[u]

    gamma[n_, m_, u_] := 2 Exp[(Sqrt[u])/(1 - (m/n)^(3/2))]

    ClearAll[efvc]
    efvc[n_, m_, u_] /; n == 0 := 0
    efvc[n_, m_, u_] /; n == m := -(2/Pi)*Sin[Pi*n]
    efvc[n_, m_, 
      u_] := -(((2 bb[n, m, u])/Pi)) (Sin[(Pi*n)/(bb[n, m, u])]) (Cos[(Pi*m)/
         gamma[n, m, u]])


    data = Import["C:\\Users\\caioa\\Documents\\Pasta1.xls"]


    {{{0.508224, 4.52*10^-7, 0.2}, {0.500808, 7.99*10^-6, 0.5}, {0.502848, 
       0.000143831, 1.}, {0.50025, 0.000845692, 1.5}, {0.504386, 0.000448702, 
       2.}, {0.512548, 0.000124658, 2.5}, {0.509866, 0.0000426, 3.}, {0.509804, 
       0.000045, 3.5}, {0.511647, 0.000148473, 4.}, {0.50246, 0.000047, 
       4.5}, {0.507061, 0.0030538, 5.}, {0.500444, 0.0000483, 5.5}, {0.506678, 
       0.0000495, 6.}, {0.501696, 0.000669212, 6.5}, {0.508953, 0.0000503, 
       7.}, {0.505067, 0.0000501, 7.5}, {0.501641, 0.000498973, 8.}, {0.509878, 
       0.00529143, 8.5}, {0.507094, 0.0000507, 9.}, {0.504594, 0.00433331, 
       9.5}, {0.502338, 0.0000504, 10.}}}

    NonlinearModelFit[data, (efvc), {A}, {n, m, u}]


    NonlinearModelFit::fitd: First argument {{{0.508224,4.52*10^-7,0.2},{0.500808,7.99*10^-6,0.5},{0.502848,0.000143831,1.},{0.50025,0.000845692,1.5},{0.504386,0.000448702,2.},{0.512548,0.000124658,2.5},<<9>>,{0.505067,0.0000501,7.5},{0.501641,0.000498973,8.},{0.509878,0.00529143,8.5},{0.507094,0.0000507,9.},{0.504594,0.00433331,9.5},{0.502338,0.0000504,10.}}} in NonlinearModelFit is not a list or a rectangular array.
Attachments:
POSTED BY: caiocustodio
6 Replies

Your data isn't a rectangular array: it's a list containing a single element, and that single element is a rectangular array. Use data[[1]].

POSTED BY: John Doty
Posted 6 years ago

Now it returned:

NonlinearModelFit::fitc: Number of coordinates (2) is not equal to the number of variables (3).
POSTED BY: caiocustodio

It means what it says. Your data items contain three numbers, which it interprets as two independent variables and a quantity derived from them. Your list of variables is {n, m, u}. Three independent variables. I have no idea what you mean by your parameter A or how you expect to inform your function evfc of its value, or of the values of the independent variables.

POSTED BY: John Doty
Posted 6 years ago

I called A just a little bit of the equation so I could test if I could achieve what I am looking for. I want to improve the form of efvc, but I can change some bits of it, because the overall form has a physical meaning behind it. I don't how to make it possible. I need the three variables {n, m, u} without fixing one of them, so I can obtain a efvc form that works well in all regimes.

I made some changes, where now my table is {n, m, u, f}, here calling fjust to say it's the solution of the equation. Getting now another error that seems to be caused because I am using roots, I don't know.

Attachments:
POSTED BY: caiocustodio

If you wish to get advice, post your code.

Remember that Mathematica is an expression rewriting language. Consider your code:

NonlinearModelFit[data, (efvc), {A}, {n, m, u}]

NonlinearModelfit works by substituting values for the variables and parameters into the given formula. The formula here is (efvc). It contains none of A, n, m, u. The fact that you've told Mathematica how to rewrite expressions of the form evfc[_,_,_] is irrelevant: you have no such expression here. The pattern names in your definition of evfc have no connection to names of variables and parameters elsewhere.

POSTED BY: John Doty
Posted 6 years ago

I post both my inicial tests and what I have changed as attachments. Maybe if I try to write my equation as a big one instead of four. My biggest problem is the Bessel function which I don't know that much of how implement it.

POSTED BY: caiocustodio
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract