Problem to solve integration

17 次查看(过去 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!

采纳的回答

Star Strider
Star Strider 2021-11-24
Change this —
f = @x sin(x);
to this —
f = @(x) sin(x);
That should work.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by