constraints - matlab - plot trendline with specific condition(e.g. slope at specific x value, must past through specific point,etc) -
good day.
i got scatter plotted in matlab. want plot trendline of data on plot well. instead of normal quadratic curve fitting, want constrain trendline slope=0 when x=0. how achieve that?
and out of curiosity, how constrain trendline must pass through specific point? setting intercept in excel?
and can trendline have multiple constrain described above?
thank you.
you want fit quadratic, a*x^2+b*x+c
data, want derivative 0 somewhere. constraint relate variables. derivative 2*a*x+b
0 @ x=0
, need b=0
. trying fit a*x^2+c
data. not difficult,
a=[x(:).^2 ones(size(x(:)))]; coeffs=a\y(:); fittedy=@(x) coeffs(1)*x.^2+coeffs(2)
and fittedy(x)
gives value of fitted curve @ x
.
if want fit have value, rather derivative somewhere, similar thing. want fit equal 1 @ x=1
. a+b+c=1
, set c=1-b-a
, function fit a*x^2+b*x+1-b-a
.
you can use 3 such constraints, using 3 constraints (in general) uniquely determine quadratic function, there no parameters left fit with.
Comments
Post a Comment