Prev: Linear fit forcing zerointercept: How to compute confidence interval
Next: Determining derivative and integral coefficients
From: R P on 12 Nov 2009 19:12 I'm trying toget the integral from 3 to 4 from a spline fit function I'm having problems with both the fit (it is not close from my points) and the integral (it doesnt work with csaps outut: an struct) Can you please help me? My code is shown below: Thanks %data points X=[0,0.7,1.5,2.3,3.1,3.9,4.6,5.4,6.2,7.0;]; Y=[454,5097,10915,5368,1002,6197,5661,1006,367,992;]; %spline fit dx = diff(X); weights = ([dx 0]+[0 dx])/2; spline_function = csaps(X,Y,5000, [], weights); %spline fit test: something is wrong... x_spline=0:0.1:7; y_spline=fnval(spline_function,x_spline); plot(X,Y,'.',x_spline,y_spline,'-'); %: I'd like to get the integral from 3 to 4... %it's not working int = integrate(spline_function,4,3) %the error message: %??? Undefined function or method 'integrate' for input arguments of type 'struct'.
From: R P on 13 Nov 2009 07:29 Other ideas? "R P" <rpavao(a)colband.com.br> wrote in message <hdi88h$c9r$1(a)fred.mathworks.com>... > I'm trying toget the integral from 3 to 4 from a spline fit function > I'm having problems with both the fit (it is not close from my points) > and the integral (it doesnt work with csaps outut: an struct) > Can you please help me? > My code is shown below: > Thanks > > > %data points > X=[0,0.7,1.5,2.3,3.1,3.9,4.6,5.4,6.2,7.0;]; > Y=[454,5097,10915,5368,1002,6197,5661,1006,367,992;]; > > %spline fit > dx = diff(X); > weights = ([dx 0]+[0 dx])/2; > spline_function = csaps(X,Y,5000, [], weights); > > %spline fit test: something is wrong... > x_spline=0:0.1:7; > y_spline=fnval(spline_function,x_spline); > plot(X,Y,'.',x_spline,y_spline,'-'); > > %: I'd like to get the integral from 3 to 4... > %it's not working > int = integrate(spline_function,4,3) > %the error message: > %??? Undefined function or method 'integrate' for input arguments of type 'struct'.
From: Bruno Luong on 13 Nov 2009 07:40 "R P" <rpavao(a)colband.com.br> wrote in message <hdjjee$519$1(a)fred.mathworks.com>... > Other ideas? Sure, pull out the polynomial on each sub-interval from the spline then integrate then sum up. Bruno
From: Jon Cherrie on 16 Nov 2009 05:49
Comments below ... "R P" <rpavao(a)colband.com.br> wrote in message <hdi88h$c9r$1(a)fred.mathworks.com>... > I'm trying toget the integral from 3 to 4 from a spline fit function > I'm having problems with both the fit (it is not close from my points) > and the integral (it doesnt work with csaps outut: an struct) > Can you please help me? > My code is shown below: > Thanks > > > %data points > X=[0,0.7,1.5,2.3,3.1,3.9,4.6,5.4,6.2,7.0;]; > Y=[454,5097,10915,5368,1002,6197,5661,1006,367,992;]; > > %spline fit > dx = diff(X); > weights = ([dx 0]+[0 dx])/2; > spline_function = csaps(X,Y,5000, [], weights); Try 0.5 rather than 5000 for the third argument. Generally a value between zero and one will be good for this parameter. Alternatively, use empty, [], and CSAPS will guess a value for you. See "help csaps" for more details. > > %spline fit test: something is wrong... > x_spline=0:0.1:7; > y_spline=fnval(spline_function,x_spline); > plot(X,Y,'.',x_spline,y_spline,'-'); See "help fnplt" > > %: I'd like to get the integral from 3 to 4... > %it's not working > int = integrate(spline_function,4,3) > %the error message: > %??? Undefined function or method 'integrate' for input arguments of type 'struct'. See "help fnint", .e.g, >> integral_function = fnint( spline_function ) >> int = fnval( integral_function, 4 ) - fnval( integral_function, 3 ) Cheers, --Jon |