Problem to solve integration
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Deck Zhan Sim
am 24 Nov. 2021
Beantwortet: Star Strider
am 24 Nov. 2021
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 Kommentare
Akzeptierte Antwort
Star Strider
am 24 Nov. 2021
Change this —
f = @x sin(x);
to this —
f = @(x) sin(x);
That should work.
.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!