Derived Function Handle does not support integration operation, frustrating!
古いコメントを表示
Try this piece of code, which works fine.
a=1;b=2;
% A two-variate function
f2= @(x,y) x+y;
derivedF2=@(x) integral(@(y) f2(x,y), a,b);
% Test the evaluation of the derived function handle
derivedF2(0);
% Test the integration of the derived function handle
% integralVal=integral(derivedF2,a,b);
% integralVal=integral(@(x) derivedF2(x),a,b);
% Test plotting of the derived function handle
figure(11);
ezplot(@(x) arrayfun(derivedF2,x));
But if you uncomment the lines starting with integralVal. The code breaks.
Apparently, the derived function handle does not support integration operation, or have I missed something?
2 件のコメント
Walter Roberson
2017 年 7 月 12 日
You have not defined a or b, so the code will not run.
Richard
2017 年 7 月 14 日
採用された回答
その他の回答 (1 件)
Walter Roberson
2017 年 7 月 12 日
integralVal = integral(derivedF2, a, b, 'ArrayValued', true);
Or
integralVal = integral( @(X) arrayfun(derivedF2, X), a, b);
The basic problem is that integral() passes a vector as the first argument and the objective function must return a value for each member of the vector, and that happens at both levels when you have a nested integral() call.
カテゴリ
ヘルプ センター および 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!