Nested integral within integral2

21 ビュー (過去 30 日間)
Juan
Juan 2013 年 8 月 23 日
I'm attempting to take the double integral (using integral2) of a function that is defined by an integral.
Here is what I am currently attempting:
t=linspace(0,1,50);
fun_1= @(v) exp(.071*v)
fun = @(x,y) 0.14*0.00607*integral(@(u)fun_1(u),0,x).*exp(-(x-y).^2).*0.14*0.00607*integral(@(u)fun_1(u),0,x);
for i=2:length(t)
for j=i:length(t)
A(i,j)=integral2(fun,t(i-1),t(i),t(j-1),t(j));
end
end
I'm receiving the error
Error using integral (line 86) A and B must be floating point scalars.
Can anyone provide any information on how to fix this problem.

採用された回答

Mike Hosea
Mike Hosea 2013 年 8 月 24 日
The problem here is that integral2 requires that the integrand accept arrays as inputs and return arrays as outputs, but integral only accepts scalars for the left- and right-hand end points. You just need to vectorize the call to integral. Also, I assume you meant to use y in the second call to integral.
n = 12; % Increase to 50 when you're ready, but be prepared for a wait!
t = linspace(0,1,n);
fun_1 = @(v) exp(.071*v);
int_fun_1_scalar_inputs_only = @(x)integral(fun_1,0,x);
int_fun_1_vectorized = @(x)arrayfun(int_fun_1_scalar_inputs_only,x);
fun = @(x,y) 0.14*0.00607*int_fun_1_vectorized(x).*exp(-(x-y).^2) ...
.*0.14*0.00607.*int_fun_1_vectorized(y);
A = zeros(n); % Preallocate A
for i=2:n
for j=i:n
A(i,j)=integral2(fun,t(i-1),t(i),t(j-1),t(j));
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by