integrate function

5 次查看(过去 30 天)
kostas
kostas 2011-8-25
Hi!!!
I would like to ask if anyone knows what's the appropriate way to calculate the integral of this function
function out = Gr(u,x,Kt,i)
out= exp(-(u.^2)).*frustration_function2(u,x,Kt,i);
end
The integrating variable is u, and the limits are [1e-4,1e4]
Thanks!!

回答(2 个)

Andrei Bobrov
Andrei Bobrov 2011-8-25
variant
x = ...;
Kt = ...;
i = ...;
quad(@(u)exp(-(u.^2)).*frustration_function2(u,x,Kt,i),
1e-4,1e4)
  7 个评论
Andrei Bobrov
Andrei Bobrov 2011-8-25
Hi Walter! Your last comment - the correct answer.
Bellow example, with use Maple Toolbox.
>> intd=@(Kt,i1)quad(@(x)exp(x).*arrayfun(@(X)quad(@(u)u+X+Kt+i1,0,1),x),0,1)
intd =
@(Kt,i1)quad(@(x)exp(x).*arrayfun(@(X)quad(@(u)u+X+Kt+i1,0,1),x),0,1)
>> intd(3,3)
ans =
12.169
>> syms Kt i1 x u
int(exp(x)*int(u+x+Kt+i1,u,0,1),x,0,1)
ans =
1/2 - Kt - i1 + 1/2 exp(1) + exp(1) Kt + exp(1) i1
>> double(subs(ans,[Kt,i1],[3,3]))
ans =
12.169
>>
Walter Roberson
Walter Roberson 2011-8-25
Ah good... it was around 4 AM when I wrote that, so I'm glad to see that I didn't do much worse than miss a "(" in the inner anonymous function!

请先登录,再进行评论。


kostas
kostas 2011-8-25
i mean that the result of the quad need to be scalar
  1 个评论
Walter Roberson
Walter Roberson 2011-8-25
The results of the quad cannot be scalar. My sentence "The function y = fun(x) should accept a vector argument x and return a vector result y, the integrand evaluated at each element of x." was a direct quote from the reference documentation for quad. quad does not just do one evaluation at a time: it selects a number of x and requests that the fun do the evaluation with respect to each of them and return the vector of corresponding answers.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by