Integration of a function

4 ビュー (過去 30 日間)
Jithin D Mathew
Jithin D Mathew 2020 年 11 月 21 日
コメント済み: Jithin D Mathew 2020 年 11 月 24 日
syms x
a = x^6 + 5*x^4 +78
b = diff(a)
c = diff(b)
d = c^2
e = integral(d, x, 0, 3)
Error using integral (line 82)
First input argument must be a function handle.
I am getting this error
Please Help

採用された回答

John D'Errico
John D'Errico 2020 年 11 月 21 日
編集済み: John D'Errico 2020 年 11 月 21 日
It can be confusing at times I have seen for newcomers to know which tools apply where, because we have symbolic tools and numerical tools. They often live in subtly different sandboxes.
You know how to differentiate symbolic expressions. That used diff. But you need to understand that integral is a tool for definite NUMERICAL integration. For a symbolic integration, you use int.
syms x
a = x^6 + 5*x^4 +78;
b = diff(a);
c = diff(b);
d = c^2
d = 
e = int(d, x, 0, 3)
e = 
For example, you would use integral to compute a definite integral of a function handle or a function defined in an m-file. For example:
fun = @(x) x.^2 + 2;
integral(fun,1,3)
ans = 12.6667
I could have converted the expression in the variable d, into a function handle. Once it is a function handle, now numerical computations in double precision will apply to it. Then I could have used integral.
dfun = matlabFunction(d)
dfun = function_handle with value:
@(x)(x.^2.*6.0e+1+x.^4.*3.0e+1).^2
integral(dfun,0,3)
ans = 3.2680e+06
And that should be the same number as e, when expressed as a decimal. Using double, we see:
double(e)
ans = 3.2680e+06
  1 件のコメント
Jithin D Mathew
Jithin D Mathew 2020 年 11 月 24 日
Thanks man

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by