Trapezoidal rule in MATLAB
Afficher commentaires plus anciens
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.
Réponses (1)
Rava Sash
le 15 Mai 2018
0 votes
Catégories
En savoir plus sur Splines dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!