how do I do Integration

2 ビュー (過去 30 日間)
Ls
Ls 2021 年 10 月 5 日
編集済み: DGM 2021 年 10 月 5 日
when f(x)=2,x1=0.1 and x2=0.5. How do i do integration of f(x) from x1 to x2

採用された回答

DGM
DGM 2021 年 10 月 5 日
編集済み: DGM 2021 年 10 月 5 日
For a constant function like that, you could just do it geometrically:
f = 2;
xrange = [0.1 0.5];
s = f*abs(diff(xrange))
s = 0.8000
For a general symbolic approach, start with something like this instead
syms x
f = 2 + 0*x; % this just forces f to be a symbolic expression
s = int(f,[0.1 0.5])
s = 
s = double(s) % maybe you want a numeric representation instead
s = 0.8000
Try another
f = 2*sin(x) + 5*x + 3*x^2; % a bit more complicated
s = int(f,[0.1 0.5])
s = 
  2 件のコメント
Ls
Ls 2021 年 10 月 5 日
When i run it it shows an error stating syms requires symbolic math toolbox. How so i solve this problem
DGM
DGM 2021 年 10 月 5 日
編集済み: DGM 2021 年 10 月 5 日
Oh. I assumed you had that. You can always do it numerically instead:
f = @(x) 2 + 0*x; % define f as an anonymous function
s = integral(f,0.1,0.5)
s = 0.8000
f = @(x) 2*sin(x) + 5*x + 3*x.^2;
s = integral(f,0.1,0.5)
s = 0.9588

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by