Featured post
matlab - Curve fitting without toolbox -
without curve fit toolbox how fit function data in matlab?
in particular, how fit function isn't polynomial, e.g., if want fit function y = x^(1/3) + 5 not integer?
if know form of function want fit not know parameters, can use fminsearch
find parameters fit data. if have data (possibly noisy) want fit y=x^a + b
where a
and b
are unknown (here assume true values a=1/3
, b=5
) how i'd have quick answer:
here generate data (you not have in real life case)
>> x = linspace(0,5,10); >> y = x.^(1/3) + 5; >> y_noisy = y + 0.1*rand(size(y));
then define function want minimize respect a
, b
, minimize fminsearch
. in case, minimize integral of square of difference between data , function used fit. below have defined 2 functions, 1 noisy data, , 1 without noise. see in absence of noise recover values of a
and b
.
nb: fminsearch
wotks vector of parameters (v
in case). took a=v(1)
and b=v(2)
. have provide initial guess v
(here [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
last comment, in cases have constraints on values of a
and b
it useful perform change of variable. example if know a>0
, might want identify log(a)
, convert identified value a
.
hope helps.
a.
- Get link
- X
- Other Apps
Comments
Post a Comment