Data fitting with custom equation

조회 수: 4 (최근 30일)
Somnath Kale
Somnath Kale 2021년 4월 15일
댓글: Somnath Kale 2021년 6월 27일
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.

채택된 답변

William Rose
William Rose 2021년 4월 15일
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
William Rose
William Rose 2021년 4월 16일
Somnath, I will look at it later today.
William Rose
William Rose 2021년 4월 16일
편집: William Rose 2021년 4월 16일
@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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Somnath Kale
Somnath Kale 2021년 4월 17일
편집: Somnath Kale 2021년 4월 17일
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
William Rose
William Rose 2021년 4월 18일
@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 2021년 6월 27일
@William Rose I am facing issue in fitting on complicated fuction. i have posted new question.
please take look and help if possible!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by