Data fitting with custom equation

3 views (last 30 days)
Hi
I am facing some issue in the data fitting with the equation. I wanted to fit to my data with eqauation attached in the image. please also suggest what type of fuction we can fit or not fit. my x and y are as fillow.
x = 1.00E-07 2.00E-07 5.00E-07 1.00E-06 2.00E-06 5.00E-06 1.00E-05 2.00E-05 5.00E-05 1.00E-04 2.00E-04 5.00E-04 1.00E-03 2.00E-03 5.00E-03
y = 2.3800 4.4800 6.4500 9.0200 13.2400 16.2600 18.9700 22.9900 26.3300 28.7800 30.3100 31.6500 31.9500 32.0500 32.3400
if possible let me kno the code also.

Accepted Answer

William Rose
William Rose on 15 Apr 2021
fmincon() is a very good general purpose routine to find the parameters that give a good fit to your data.
To use fmincon(), you need to write a function that returns the error between your data and the predictions from your equation. Usually the error is defined as the sum of the squared errors between the data and the predicitons. You need to pass to fmincon() the name of that function, and an initial guess for the parameters, and some bounds on the parameters (i.e a vector of the maximum acceptable value of each parameter and a vector of the minimum acceptable value for each). Then fmincon() searches parameter space to find the set of parameters that minimize the error and which obey the maximum and minimum constraints.
You already have a function to fit the data (in your image file). It has 3 adjustable parameters: . Use that to fit the data. Do you need another functionto compare? If so, try a straight line.
  8 Comments
William Rose
William Rose on 16 Apr 2021
Somnath, I will look at it later today.
William Rose
William Rose on 16 Apr 2021
Edited: William Rose on 16 Apr 2021
@Somnath Kale, I do not get an error when I run it. I am running Matlab 2018b. I see the following output in the console window:
>> SomnathMain
Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current step is less than
the default value of the step size tolerance and constraints are
satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
Best fit: Pmax=35.769, alpha=0.532, tau=7.18e-06
>>
Try changing line 4 in SomnathMain.m to
p=fmincon(@SomnathsFunc,p0);
That works equally well for me. Or replace line 4 with the following two lines. Note that there are seven [ ] in the second line. This also works fine for me, and gives the same results as above.
options=optimset;
p=fmincon(@SomnathsFunc,p0,[],[],[],[],[],[],[],options);
Try it.

Sign in to comment.

More Answers (1)

Somnath Kale
Somnath Kale on 17 Apr 2021
Edited: Somnath Kale on 17 Apr 2021
I tried both the suggetions, in R2018b, R2020b and R2021a version showing same error. I checked in the community also several peoples faced this issue "Not enough input arguments". Is it because of some installation issue? here I have attached screenshot with all suggestion and respective errors. please take a look if this helps to juge where it going wrong or I am making some mistake!
  4 Comments
William Rose
William Rose on 18 Apr 2021
@Somnath Kale, You're welcome. Thank you very much for your kind comments. If I have problems with instrument control, I will be sure to conatct you!
Somnath Kale
Somnath Kale on 27 Jun 2021
@William Rose I am facing issue in fitting on complicated fuction. i have posted new question.
please take look and help if possible!

Sign in to comment.

Categories

Find more on AI for Signals and Images in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!