0
$\begingroup$

So, I'm trying to adjust a model to an experiment, this model, more specifically:

While:

The only parameter to be adjusted is I, the problem here is, I not only need to plot this with all the errors and so, as I need to fit the integral of this in respect of "r" from 0 to 2*pi, with "d" being the x-axis value.

I'm extremely new to Mathematica, I've been barely able to just plot the data points with errors, without any fitting whatsoever, how should I proceed? And, is it feasible at all?

Oh,and E_1/E_2 are complete elliptic integrals of first and second kind, respectively…

Edit: This is my current code, however it doesn't wields me more than a bunch of warnings and errors, and, this is the actual model implemented:

$\endgroup$
  • $\begingroup$ Can you post the data as well? $\endgroup$ – Pillsy Dec 1 '17 at 11:29
  • $\begingroup$ Of course!.And, this is the code I've been (trying to) working in, in the last hours. $\endgroup$ – User Dec 1 '17 at 11:31
  • $\begingroup$ In your code Sqrt[_] (like all functions) must use square brackets rather than parentheses. And the call to the function field must include its arguments. $\endgroup$ – Bob Hanlon Dec 1 '17 at 13:50
  • $\begingroup$ @BobHanlon Oh, Thank you! Such a simple problem… C++ Habits… However, I have a new problem, here's my current code, now it gives me "FindFit::fitm: Unable to solve for the fit parameters; the design matrix is nonrectangular, non-numerical, or could not be inverted.", and I don't really know what it means. $\endgroup$ – User Dec 1 '17 at 17:04
  • $\begingroup$ New updated current version…, I'm still not sure what the problem may be, I've tried all the suggestions I could find, and, yet, nothing… $\endgroup$ – User Dec 1 '17 at 18:11
1
$\begingroup$

Download your data file and delete the .txt extension before importing.

data = Import["/Users/roberthanlon/Downloads/coil_datawu.csv"];

The data then consists of lists of pairs of numbers rather than a string.

Union[{Head[#], Length[#], And @@ (NumberQ /@ #)} & /@ data]

(* {{List, 2, True}} *)

(* mu=4 e-7*Pi *)

mu = 4*10^-7 * Pi; (* Assuming you intended this *)
Radius = 0.149 // Rationalize;
radius = 0.0582 // Rationalize;
frequency = 8313 // Rationalize;

There is no need to restrict the arguments of field to be numeric since it does not use numeric techniques.

field[r_, x_, mu_, Radius_, frequency_] := 
  mu*frequency*
   Sqrt[2]/(2*Pi*
      Sqrt[x^2 + (Radius + r)^2])*((Radius^2 - x^2 - 
         r^2)/(x^2 + (r - Radius)^2)*
      EllipticE[Sqrt[4*r*Radius*(x^2 + (Radius + r)^2)^(-1)]] + 
     EllipticK[Sqrt[4*r*Radius*(x^2 + (Radius + r)^2)^(-1)]]);

However, define the model using NIntegrate which then necessitates that the arguments to model be numeric. Note that i must also be an argument and the integrand should not be enclosed in List brackets.

Clear[model]

model[i_?NumericQ, x_?NumericQ, mu_?NumericQ, Radius_?NumericQ, 
  frequency_?NumericQ] := 
 2*i*Pi*NIntegrate[field[r, x, mu, Radius, frequency], {r, 0, radius}]

solution = FindFit[data, model[i, x, mu, Radius, frequency], {{i, 0.7}}, x]

(* {i -> 12.7577} *)

{xmin, xmax} = MinMax[data[[All, 1]]];

However, the model does not appear to fit the data.

Plot[model[i, x, mu, Radius, frequency] /. solution,
 {x, xmin, xmax},
 Epilog -> {Red, AbsolutePointSize[3], Point[data]}]

enter image description here

NonlinearModelFit produces the same results.

nlm = NonlinearModelFit[data, model[i, x, mu, Radius, frequency], {{i, 0.7}}, 
   x];

nlm["BestFitParameters"]

(* {i -> 12.7577} *)

Plot[nlm[x], {x, xmin, xmax},
 Epilog -> {Red, AbsolutePointSize[3], Point[data]}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.