-
Notifications
You must be signed in to change notification settings - Fork 0
/
createFit.m
43 lines (35 loc) · 1.11 KB
/
createFit.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function [fitresult, gof] = createFit(H, R)
%CREATEFIT(H,R)
% Create a fit.
%
% Data for 'untitled fit 2' fit:
% X Input : H
% Y Output: R
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 29-Nov-2016 17:02:32
%% Fit: 'untitled fit 2'.
[xData, yData] = prepareCurveData( H, R );
Hr=1774;
delta_H=70;
k1=-962007.8274;
% Set up fittype and options.
ft = fittype( 'k1*(4*(x-Hr))/(delta_H^2+4*(x-Hr)^2)^2+k2*((delta_H^2-4*(x- Hr)^2)/(delta_H^2+4*(x-Hr)^2)^2)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [-Inf];
opts.StartPoint = [0.0461713906311539];
opts.Upper = [Inf];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 2' );
h = plot( fitresult, xData, yData );
legend( h, 'R vs. H', 'untitled fit 2', 'Location', 'NorthEast' );
% Label axes
xlabel H
ylabel R
grid on