matlab - integral of a series which is a function -
i quite lost matlab code.i appreciate help. need integrate series, function of variable x
, on support of x
.
i run following:
m=10; % finite summation uptill m %step1: create series function: \sum_{1}_{m}(x^{n}) series=@(x,n)(sum(x.^(1:n))); %styep2: call function m=10, x still undefined ser=@(x)series(x,m); % step3: integrate on x in given space x h=integral(ser,1,2);
i get:
error using .^ matrix dimensions must agree. error in @(x,n)(sum(x.^(1:n))) error in @(x)series(x,m) error in integralcalc/iteratescalarvalued (line 314) fx = fun(t); error in integralcalc/vadapt (line 133) [q,errbnd] = iteratescalarvalued(u,tinterval,pathlen); error in integralcalc (line 76) [q,errbnd] = vadapt(@atobinvtransform,interval); error in integral (line 89) q = integralcalc(fun,a,b,opstruct); error in test (line 9) h=integral(ser,1,2);
any suggestions?
integral
requires function integrated able handle vector arguments, ser
has able evaluate ser([1 2 3])
example.
to allow ser
deal vector inputs, use arrayfun
apply series
each element of input x
individually:
ser=@(x) arrayfun(@(z)series(z,m),x);
Comments
Post a Comment