matlab - What's wrong with the use of arrayfun and bsxfun? -
i want integrate function follows:
in code, define indicator function follows:
pconstfundingrange=[0:0.25:2,inf]; pconstfunding=[0,tempfundinginitialpara,0]; % note tempfundinginitialpara constant each interval) fundinginitial=@(t)... arrayfun(@(s)pconstfunding(find(s<pconstfundingrange,1,'first')),t);
with function defined, define function: integral of fundinginitial
:
fundinginitialterm=... @(t,t)arrayfun(@(s1,s2)integral(fundinginitial,s1,s2),t,t);
my goal enter 2 vectors: vec1=[1,2]'
, vec2=[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]
, compute integral of given function f(s)
follows:
hence, use following code: bsxfun(@(t,t)fundinginitialterm(t,t),vec1',vec2)
however, outputs following error message:
error using
arrayfun
all of input arguments must of same size , shape.
previous inputs had size 1 in dimension 1. input #3 has size 41
how solve problem?
this way integrals can computed:
f= @(s) sqrt(s); vec1=[1,2] ; vec2=[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]; [v2,v1]=meshgrid(vec2,vec1); arrayfun(@(low,up) integral(f,low,up),v2 ,v1)
Comments
Post a Comment