Trapezoidal rule in MATLAB
Show older comments
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.
Answers (1)
Rava Sash
on 15 May 2018
0 votes
Categories
Find more on Splines in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!