How to compute integral when one of the limits is a vector

9 ビュー (過去 30 日間)
Maurilio Matracia
Maurilio Matracia 2020 年 9 月 21 日
コメント済み: Ameer Hamza 2020 年 9 月 21 日
Hello everyone,
I am trying to use the function integral to evaluate a function handle in a vector, such as:
FunctionToEvaluate = @(x) integral(@(z) z.^2+1, 0, x, 'ArrayValued',1)
EvaluatedFunction = FunctionToEvaluate([1 2 3])
but I am getting an error saying:
Error using integral (line 85)
A and B must be floating-point scalars.
Is there any way to avoid this error and evaluate the function in a vector?
Thank you in advance for your help!

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 9 月 21 日
編集済み: Ameer Hamza 2020 年 9 月 21 日
If you want to use all the points in x as the limits one after the other, then following is the way to do that
FunctionToEvaluate = @(x) arrayfun(@(x_) integral(@(z) z.^2+1, 0, x_) , x);
EvaluatedFunction = FunctionToEvaluate([1 2 3])
Result
>> EvaluatedFunction
EvaluatedFunction =
1.3333 4.6667 12.0000
  2 件のコメント
Maurilio Matracia
Maurilio Matracia 2020 年 9 月 21 日
That's great, thank you very much!
Ameer Hamza
Ameer Hamza 2020 年 9 月 21 日
I am glad to be of help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by