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

2 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 26 de Abr. de 2012
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)
  2 comentarios
john birt
john birt el 26 de Abr. de 2012
Thank you, it works like a dream!, now to apply this to my huge function and see what happens.
Big thank you. :-)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by