我想使用quadgk
集成一维函数,但是要包含在被积函数中的参数的不同值。是否有捷径可寻?下面有希望说明我的问题:
function [out] = integrand(x,t)
#Calculations
end
t = linspace(0,1,10);
q = quadgk(@integrand,0,Inf, OPT_PARAM = t); #Apply quadgk on integrand for each value in t
plot(t, q) # q is a function of t
答案 0 :(得分:1)
你能用for
循环吗?
function [out] = integrand(x,t)
%Calculations
end
t = linspace(0,1,10);
q = zeros(size(t)); % pre-allocate q
for k=1:length(t)
q(k) = quadgk(@(x)integrand(x,t(k)),0,Inf); %Apply quadgk on integrand for each value in t
end
plot(t, q) % q is a function of t
有关http://www.mathworks.co.uk/help/matlab/math/parameterizing-functions.html参数化功能的更多详细信息。