Problem to solve integration
19 ビュー (過去 30 日間)
古いコメントを表示
Hi all, I having an issue to solve this problem.
clc
clear
close all
syms x
f = @x sin(x);
a = 0;
b = pi;
prompt = ('Enter the number of subinterval,n:');
n = input(prompt);
function result_integration = midpoint(f, a, b, n)
h = (b-a)/n;
result = 0;
for i = 0:(n-1)
result = result + f((a + h/2) + i*h);
end
result_integration = h*result;
end

I would be very grateful to those can solve this matter. Thanks!
0 件のコメント
採用された回答
Star Strider
2021 年 11 月 24 日
Change this —
f = @x sin(x);
to this —
f = @(x) sin(x);
That should work.
.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!