Can I store indefinite integral using a function handle?

9 ビュー (過去 30 日間)
Kai-Lung Chu
Kai-Lung Chu 2018 年 12 月 5 日
コメント済み: Star Strider 2018 年 12 月 6 日
Is it possible to store indefinite integral in a function handle and input values?
syms x
a=@(x)x^2;
b=@(x)int(a(x));
%E.g. when x=1 b=?
b(1)
%E.g. when x is a vector b=?
%int will always output x^n, but in order to plug in a vector it has to be changed to x.^n. Is there an automatic way to add the dot? I suppose I can use for loop and calculate b for each individual x and store it in a vector
x_1=1:0.1:10;
b(x_1)

採用された回答

Star Strider
Star Strider 2018 年 12 月 5 日
See if this does what you want:
syms x
a(x) = x^2;
b(x) = int(a(x));
bfcn = matlabFunction(b)
produces:
bfcn =
function_handle with value:
@(x)x.^3./3.0
Substituting your scalar and vector:
x =
1
Out = bfcn(x)
Out =
0.3333
x =
1 3 5 7
Out = bfcn(x)
Out =
0.3333 9.0000 41.6667 114.3333
  2 件のコメント
Kai-Lung Chu
Kai-Lung Chu 2018 年 12 月 6 日
It works fine like this, thanks
syms x
a = @(x)x^2;
b = @(x)int(a(x));
c = matlabFunction(b(x));
c(1)
Star Strider
Star Strider 2018 年 12 月 6 日
As always, my pleasure.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by