I'm having trouble trying to write a 2d function with vectorized inputs that has an integral inside.
My function is as follows:
thick = 40e-9;
overlap = (@(E,T)integral2(@(x,y)exp(E.*T.*abs(x-y)),0,thick,0,thick));
If I call the function with scalar inputs, e.g. overlap(1,1), this works fine.
overlap(1,1)
ans = 1.6000e-15
However, if I call the function with vector inputs for E and T, e.g. E=1:1:10 and T=1:1:10, this does not work. I get the following:
Error using .*
Matrix dimensions must agree.
Does anyone know how to make this work with vectorized inputs?
Thanks in advance!

 채택된 답변

Walter Roberson
Walter Roberson 2018년 6월 19일

1 개 추천

overlap = @(Ev,Tv) arrayfun( @(E,T) integral2(@(x,y)exp(E.*T.*abs(x-y)),0,thick,0,thick), Ev, Tv);
This assumes that E and T are the same size and the in each case corresponding values are to be taken. The code would need to be modified if you were wanting to have E and T represent marginals for a grid output, such as if you wanted a 10 x 10 output when you pass E and T each of length 10.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by