Curve fixation without tools

Without a toolkit for curve fitting, how do you fit a function into data in MATLAB?

In particular, how do you approach a function that is not a polynomial, for example, if I want to pick up a function like y = x ^ (1/3) + 5, where it is not an integer?

+5
source share
3 answers

If you know the form of the function that you want to place but don’t know its parameters, you can use fminsearchit to find the parameters that match your data. If you have data (possibly noisy) that you want to put in y=x^a + b, where aand bare unknown (here I'm going to assume that the true values are a=1/3and b=5) d quick answer:

Here I generate my data (you did not need to do this in real life)

>> x = linspace(0,5,10);
>> y = x.^(1/3) + 5;
>> y_noisy = y + 0.1*rand(size(y)); 

, a b, fminsearch. , . : . , a b.

NB: fminsearch wotks (v ). a=v(1) b=v(2). v ( [1 1]).

>> err_noisy  = @(v) trapz(x,(y_noisy - x.^v(1)-v(2)).^2);
>> err = @(v) trapz(x,(y - x.^v(1)-v(2)).^2); 
>> v_noisy = fminsearch(err_noisy,[1 1])

v_noisy =

    0.3345    5.0594

>> v = fminsearch(err,[1 1])

v =

    0.3333    5.0000

, , a b, . , , a>0, log(a), a.

, .

.

+9

immoptibox - . , @Adrien y = x^a + b, a b marquardt immoptibox.

. sofit r, j.

function [r, j] = sofit(x, fitData)
t = fitData(:,1);
y = fitData(:,2);
r = y - (t.^x(1) + x(2));
j = -[t.^x(1).*log(t), ones(length(t),1)];
end

script marquardt .

%% function template
f = @(t, p1, p2) t.^p1 + p2;

%% sample function
a = 1/3;
b = 5;
t= linspace(1,100)';
y = f(t, a, b);

%% packaging fit data for @sofit
fitData(:,1) = t;
fitData(:,2) = y;

%% marquardt
[xfit, info, perf] = marquardt(@sofit, [1, 1], [], fitData);

%% presentation
figure;
plot(y);
hold all
plot(f(t, xfit(1,end), xfit(2,end)), 'ro');
grid;
legend('sample function', 'fitted function', 'Location','East')

() () .

sample function and fitted function using marquardt

+3

Curve Fitting ToolBox,

  • , , (, B-), :

http://www.mathworks.com/matlabcentral/fileexchange/26292-regular-control-point-interpolation-matrix-with-boundary-conditions

2.USe polyfit, to create your own dashboard from scratch ... with this you can put the function into data in MATLAB,

doc polyfit.

eg,

 help polyfit;
 help slash;

% ...

For more information on polyfit, see http://www.mathworks.com/help/techdoc/ref/polyfit.html

+1
source

All Articles