Solving equations, Numerical Integration, MSE, best fit overall parameter 'c'

1 次查看(过去 30 天)
Note: My actual functions are huge, the question uses a simple y=c*x just for illustrative purpose.
With equation y=x*c where 'x' and 'y' are vectors find 'c' a single numeric value that minimizes the sum of squared residues (y-x*c)^2.
This I can do
x = [1.4 1.5 1.6]; y = [0.2 0.31 0.43];
c = 0.1; %initial guess
f = @(c,x) x*c;
cfit = nlinfit(x,y,f,c)
which gives c=0.2217, exactly what I am looking for, all is good. But I really want to have the variable 'y' equal to an integral, like
y = int_0^1 x*c*t^2 dt.
So coded
x = [1.4 1.5 1.6]; y = [0.2 0.31 0.43];
c = 0.1; %initial guess
t=0.1:0.1:1;
f = @(c,x) trapz(t,x*c*t.^2);
cfit = nlinfit(x,y,f,c)
But this does not work.
I do not understand how to use 'trapz' (numerical integration) in this estimation setting.
.......................................
p.s. I get the error message
??? Error using ==> nlinfit at 120
Error evaluating model function '@(c,x)trapz(t,x*c*t.^2)'.
Error in ==> test88 at 7
cfit = nlinfit(x,y,f,c)
Caused by:
Error using ==> mtimes
Inner matrix dimensions must agree.

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-4-26
x = [1.4 1.5 1.6]; y = [0.2 0.31 0.43];
c = 0.1; %initial guess
t=0.1:0.1:1;
f = @(c,x) arrayfun(@(x)trapz(t,x.*c.*t.^2),x);
cfit = nlinfit(x,y,f,c)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by