function of a variable obtained from integrating a two variable function
5 ビュー (過去 30 日間)
古いコメントを表示
I have a function that depends on two variables, say x and y; f(x,y). I want to integrate with respect to x only and get a new function that depends only on y; i.e., g(y) = @(y) integral(@(y)f(x,y),lim1,lim2), where lim1 and lim2 are the limits for for x. I want to use g(y) later to carry out other operations. I cannot find a way around this problem.
0 件のコメント
採用された回答
Matt J
2014 年 9 月 16 日
編集済み: Matt J
2014 年 9 月 16 日
I think you've answered your own question. Why can't you create an anonymous function for g() just as you did in your post
g = @(y) integral(@(x)f(x,y),lim1,lim2)
and carry that around for reuse?
1 件のコメント
Mike Hosea
2014 年 9 月 16 日
You can make it more general (work with array inputs) like so
g = @(y1)arrayfun(@(y)integral(@(x)f(x,y),lim1,lim2),y1);
For example:
f = @(x,y)exp(-hypot(x,y));
lim1 = -inf;
lim2 = inf;
g = @(y1)arrayfun(@(y)integral(@(x)f(x,y),lim1,lim2),y1);
y = linspace(-10,10);
plot(y,g(y));
その他の回答 (1 件)
Mauricio
2014 年 9 月 16 日
編集済み: Matt J
2014 年 9 月 16 日
2 件のコメント
Matt J
2014 年 9 月 16 日
Set the 'ArrayValued' option to true, as the error message instructs (in all your calls to integral()).
Mike Hosea
2014 年 9 月 16 日
Or make the Base function satisfy the requirements of INTEGRAL without the ArrayValued flag, i.e. to accept an array input and return an array of the same size.
function fun=Base(z)
fun = zeros(size(z));
for k = 1:numel(fun)
RR = @(a,b)(z(k).*3.^a)./(b+1);
fun(k) = integral(@(a)RR(a,5),0,10);
end
end
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!