![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/584386/image.png)
Data fitting with custom equation
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/584386/image.png)
8 个评论
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
2021-4-17
编辑:Somnath Kale
2021-4-17
4 个评论
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!
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!