Trapezoidal rule in MATLAB
이전 댓글 표시
This is my code so far.
function v = velocity(x, route)
load route;
d = distance_km;
y = speed_kmph;
dd=0:distance_km(end);
pp=spline(d,y);
v = ppval(pp, x);
plot(d,y,'ro');
hold on
h=fplot(@(x)ppval(pp,x),[d(1),d(end)], '- b')
hold off
if (x<0 | x>d(end)) error ('Fel') end end
This is the given code that I'm supposed to use when using trapezoidal rule:
function T = trapets(func, a, b, n)
h=(b-a)/n;
x = linspace(a,b,n+1);
fx = func(v);
T = h*(sum(fx)-(fx(1)+fx(end))/2);
end
How does the trapezoidal rule work in MATLAB? I don't really know where to begin.
답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!