在matlab中只对一个变量集成两个变量的函数

时间:2014-10-09 15:45:58

标签: matlab numerical-methods

我想使用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

1 个答案:

答案 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参数化功能的更多详细信息。