1
$\begingroup$
data = {{45.65, 38.9}, {66.87, 47.7}, {79.65, 63.4}, {36.03, 
    25.81}, {64.79, 71.99}};

soln = NonlinearModelFit[data, 
(180/pi)*ArcCos (-1 + (2*(s/l)^0.5)*(Exp[-0.0001247 (l - s)^2])),
{s}, {l}, MaxIterations -> 1000]

I think my syntax is ok, but I cannot find my error. I appreciate any help...

$\endgroup$
  • $\begingroup$ Use Pi, not pi, and ArcCos[...], not ArcCos(...), but even with those fixes it is still complaining about a vector of Complex values instead of Real values. $\endgroup$ – Bill Nov 9 '14 at 1:19
2
$\begingroup$

In addition to correcting the syntax errors, having some approaching to starting values of parameters will help get desired fit, e.g. (using the definition from Nasser's correction of syntax errors and the data)

Manipulate[
 Plot[f /. s -> p, {L0, 20, 70}, Epilog -> Point@data], {p, 20, 40}]

enter image description here

so fitting:

nlm = NonlinearModelFit[data, {f, s > 0}, {{s, 35}}, {L0}, 
  MaxIterations -> 1000]

You can best fit for single parameter:

nlm["BestFitParameters"]

yields: {s -> 35.094}

You can explore model using nlm["Properties"] and there are a number of excellent answers if you search this site.

| improve this answer | |
$\endgroup$
1
$\begingroup$

syntax errors and not good choice of l as variable name as it looks like 1. Also need a constraint added to avoid complex values errors

Clear[s, L0];
data = {{45.65, 38.9}, {66.87, 47.7}, {79.65, 63.4}, 
   {36.03, 25.81}, {64.79, 71.99}};
f = (180/Pi)*ArcCos [-1 + (2*(s/L0)^0.5)*(Exp[-0.0001247 (L0 - s)^2])];
model = NonlinearModelFit[data, {f, s > 0}, {s}, {L0}, MaxIterations -> 1000]
   // Normal

Mathematica graphics

| improve this answer | |
$\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.