How to use quadgk with arrayvalued functions?
Show older comments
Hi, I want to numerically integrate an array valued function using Gauss-Kronrod quadrature. The input E to the integral function, func_charge , is a scalar and the output of this function Gpd is an 240X1 array which I want to integrate using quadgk.
I have used both quadv and integral to integrate this function and both these methods work and now I want to try with quadgk. I have used the following command to integrate it using vectorized quadrature,
hole_den=quadv(@func_charge,low_lim,up_lim,1e-7,[],T,H_ms,H_ms_sup,u_ms,num_mode,nx)
While with integral the following commands seems to work
Gpd=@(E)func_charge(E,T,H_ms,H_ms_sup,u_ms,num_mode,nx);
hole_den=integral(Gpd,low_lim,up_lim,'ArrayValued',true,'RelTol',0,'AbsTol',1e-4);
Using a similar command with quadgk with arrayfun option
Gpd=@(E)func_charge(E,T,H_ms,H_ms_sup,u_ms,num_mode,nx);
hole_den=quadgk(arrayfun(Gpd,low_lim,up_lim));
gives the following error:
Error using charge_calc>@(E)func_charge(T,H_ms,H_ms_sup,u_ms,num_mode,nx) Too many input arguments.
Error in charge_calc (line 13) hole_den=quadgk(arrayfun(Gpd,low_lim,up_lim));*
charge_calc is the function where the integration is carried out(which calls quadgk).
I have defined the function func_charge in the following manner
Gpd=func_charge(E,T,H_ms,Au,u_ms,num_mode,nx)
As can be seen I am passing 7 arguments to the function func_charge as required but I am still getting the above mentioned error. I have also tried by removing the first argument E since I am using a function handle for the function func_charge. In this case also I am getting the same error.
Can someone please suggest how to use quadgk to integrate an arrayvalued function. I am currently using Matlab 2016a.
Thanks,
Dibakar
Answers (0)
Categories
Find more on Numerical Integration and Differentiation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!