# Non linear fit help

**URL:** <https://community.wolfram.com/t/non-linear-fit-help/6114>\
**Category:** Questions\
**Tags:** algebra, discrete-mathematics\
**Created:** [July 8, 2015, 7:27pm UTC](https://community.wolfram.com/t/non-linear-fit-help/6114 "2015-07-08T19:27:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![suvadipmandal31](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/suvadipmandal31/32/17402_2.png) [@suvadipmandal31](https://community.wolfram.com/u/suvadipmandal31)\
**Post date:** [July 8, 2015, 7:27pm UTC](https://community.wolfram.com/t/non-linear-fit-help/6114/1 "2015-07-08T19:27:24Z")

</div>

Hi all,

I am trying to fit a series of data using a non linear equation. I have tried with the [NonlinearModelFit](https://reference.wolfram.com/language/ref/NonlinearModelFit.html) function but it gives me unsatisfactory answer.

I am attaching the data file I am working on and the non linear equation.

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![seanc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/seanc/32/34005_2.png) [@seanc](https://community.wolfram.com/u/seanc)\
**Post date:** [July 8, 2015, 8:26pm UTC](https://community.wolfram.com/t/non-linear-fit-help/6114/2 "2015-07-08T20:26:52Z")

</div>

Nonlinear fitting is an optimization problem. Most of the time, an unacceptable answer appears because a local minimum is found while searching for the least squares.

- You can use the Method option to select a different optimization method.
- Use FindFit. FindFit allows you to specify starting values for the values of the parameters. You provide an estimation of what the corrects results are to ensure that the answer converges to the solution you are looking for.

What kind of result do you expect? Does this result have a small east squares residual?

You’ve provided some data files and a PDF. Would it be possible for you to provide a notebook with some code? This would make it easier for people to guess which data set each variable referred to.

---

<div class="post-metadata">

**Author:** ![seanc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/seanc/32/34005_2.png) [@seanc](https://community.wolfram.com/u/seanc)\
**Post date:** [July 8, 2015, 8:30pm UTC](https://community.wolfram.com/t/non-linear-fit-help/6114/3 "2015-07-08T20:30:49Z")

</div>

Finally, looking at your formula…

Is x the independant variable in the formula? If so you might be able to transform the x values so this is a linear problem.

```
x = Sqrt[Log[newx]]

E^(x^2) = newx

```

When x\>1 this is an injective map that linearizes your equation.. unless I’m missing something.

---

<div class="post-metadata">

**Author:** ![suvadipmandal31](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/suvadipmandal31/32/17402_2.png) [@suvadipmandal31](https://community.wolfram.com/u/suvadipmandal31)\
**Post date:** [July 8, 2015, 8:50pm UTC](https://community.wolfram.com/t/non-linear-fit-help/6114/4 "2015-07-08T20:50:45Z")

</div>

Sir,

My expected fit is a double Gaussian fit. The parameters are n, a and b. The independent variable is x. I am attaching the mathematica file. Perhaps this will help.

---

<div class="post-metadata">

**Author:** ![seanc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/seanc/32/34005_2.png) [@seanc](https://community.wolfram.com/u/seanc)\
**Post date:** [July 8, 2015, 9:06pm UTC](https://community.wolfram.com/t/non-linear-fit-help/6114/5 "2015-07-08T21:06:49Z")

</div>

This is a common mistake, but this is not the correct way to estimate the parameters of a probability distribution.

I’m not exactly sure what you are doing in the notebook. Are you trying to fit to the CDF or Survival function of the sum of two Gaussian distributions? If so, wouldn’t the range of the points be between 0 and 1?

It doesn’t matter either way. There are correct ways to estimate the parameters of a distribution from a set of samples. The function EstimateDistribution does this.

For example, here is how you define a Mixture Distribution of two Gaussians with different means, but the same variance:

```
MixtureDistribution[{1, 1}, {NormalDistribution[m1, v], NormalDistribution[m2, v]}]

```

---

<div class="post-metadata">

**Author:** ![suvadipmandal31](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/suvadipmandal31/32/17402_2.png) [@suvadipmandal31](https://community.wolfram.com/u/suvadipmandal31)\
**Post date:** [July 8, 2015, 10:09pm UTC](https://community.wolfram.com/t/non-linear-fit-help/6114/6 "2015-07-08T22:09:48Z")

</div>

Sir,

I tried to use the FindFit function but again I have got something which should not get. I have attached the file and please tell me what is wrong.

I have got this data from an experiment and all I know is that the fit should be a double Gaussian fit of that structure.

---

<div class="post-metadata">

**Author:** ![seanc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/seanc/32/34005_2.png) [@seanc](https://community.wolfram.com/u/seanc)\
**Post date:** [July 9, 2015, 2:01pm UTC](https://community.wolfram.com/t/non-linear-fit-help/6114/7 "2015-07-09T14:01:06Z")

</div>

1. What values for the parameters are more reasonable? Try using these as starting values for FindFit.
2. What is this equation? Is it the CDF of the distribution? The PDF of the distribution? If so, your data doesn’t make any sense.
