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!