Problem to solve integration
조회 수: 25 (최근 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!