-
Notifications
You must be signed in to change notification settings - Fork 0
/
createFit1.m
38 lines (30 loc) · 1.06 KB
/
createFit1.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
function [fitresult, gof] = createFit1(H2, R2)
%CREATEFIT1(H2,R2)
% Create a fit.
%
% Data for 'untitled fit 2' fit:
% X Input : H2
% Y Output: R2
% 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:43:22
%% Fit: 'untitled fit 2'.
[xData, yData] = prepareCurveData( H2, R2 );
% 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.StartPoint = [1774 70 -962007.8274 0.754686681982361];
% 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, 'R2 vs. H2', 'untitled fit 2', 'Location', 'NorthEast' );
% Label axes
xlabel H2
ylabel R2
grid on