Friday, 15 July 2011

matlab - How do I create function handle from cfit, multiply with other function handle and integrate the term? -



matlab - How do I create function handle from cfit, multiply with other function handle and integrate the term? -

i seek integral of 2 function handles in matlab. first function handle weibull probability density function , sec function handle based on cfit created linear interpolation of single points.

x = 0:0.1:35; fun1 = @(x) wblpdf(x,weibullalpha,weibullbeta); fun2 = @(x) feval(cfitobject,x); fun3 = @(x) (fun(x).*fun2(x)); y = integral(fun3,0,35); % using quad(fun3,0,35) doesn't work either.

i receive next error:

error using integralcalc/finalinputchecks (line 515) output of function must same size input. if fun array-valued integrand, set 'arrayvalued' alternative true. error in integralcalc/iteratescalarvalued (line 315) finalinputchecks(x,fx); error in integralcalc/vadapt (line 132) [q,errbnd] = iteratescalarvalued(u,tinterval,pathlen); error in integralcalc (line 75) [q,errbnd] = vadapt(@atobinvtransform,interval); error in integral (line 88) q = integralcalc(fun,a,b,opstruct); error in test (line 7) % "test" name of script file. y = integral(fun3,0,35);

the problem must have "fun2" since code works fine e.g.

fun2 = x.^2;

note: if plot fun2 cfitobject don't error. it's possible integrate function using quad().

x = 0:0.1:35; fun2 = @(x) feval(cfitobject,x); y = quad(fun2,0,35); plot(x, fun2(x))

any help appreciated!

your code seems ok. problem fun2 cannot take vectorized input, resolved modifying fun2 (cfitobject) able handle vector input or telling software function in integral array valued:

y = integral(fun3, 0, 35, 'arrayvalued', 1);

matlab integration curve-fitting function-handle

No comments:

Post a Comment