Info

この質問は閉じられています。 編集または回答するには再度開いてください。

I have a function which is like f(a,x). I want to numerically integrate it with respect to x, for example using quad function and get factor a in the output. Can someone share how can I achieve this?

1 回表示 (過去 30 日間)
SAFAR
SAFAR 2012 年 11 月 7 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have a function which is like f(a,x). I want to numerically integrate it with respect to x, for example using quad function and get factor a in the output. Can someone share how can I achieve this?
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 11 月 7 日
Is "a" numeric for this purpose, or symbolic? If it is symbolic then you will not usually be able to do numeric integration.

回答 (1 件)

Mike Hosea
Mike Hosea 2012 年 11 月 7 日
編集済み: Mike Hosea 2012 年 11 月 7 日
Having a in the output implies symbolic integration, not numerical. I don't know your use case, but possibly you would find it acceptable to define a function of a like so:
g = @(a)integral(@(x)f(a,x),xmin,xmax)
Then you could evaluate g( a ) for any value of a that you like. If you need it to be vectorized (so that you can evaluate with a vector of a values)
h = @(a)arrayfun(g,a)
can be evaluated at a vector of a values. For example, try this
f = @(a,x)sin(a*x.^2);
g = @(a)integral(@(x)f(a,x),0,pi);
h = @(a)arrayfun(g,a);
a = linspace(0,pi,100);
plot(a,h(a))
If you don't have R2012a or later, you can use QUADGK instead of INTEGRAL. -- Mike

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by