Cumulative distance vs time graph using a velocity vs time graph
Show older comments
Hi, i have been given a formula for a velocity and a time interval and i have been tasked with producing a velocity vs time graph , a cumulative distance vs time graph as well as total distance travelled. I have currently got the velocity vs time graph working and im trying to plot a cumulative distance vs time graph by means of intergration, but i can only manage to get the total distance. I am unsure on how to go about this problem. any help would be appreciated.
Thank you
clc;
clear;
close;
hold on;
grid on;
t=0:60;
a=0;
b=60;
n=200;
area=zeros(1,60);
speed=-0.073*(t.^2)+6.1802*(t);
plot(t,speed);
dx=(b-a)/n;
x=a:dx:b;
H=zeros(1,n);
for i=1:n
fxmiddle=-0.073*((x(i)^2+x(i+1)^2))/2+6.1803*((x(i)+x(i+1))/2);
fxLeft=-0.073*(x(i)^2)+6.1802*(x(i));
fxright=-0.073*(x(i+1)^2)+6.1802*(x(i+1));
H(i)=(fxLeft+4*fxmiddle+fxright)/6;
end
%simpsons rule
integ=0;
for i=1:n
A=H(i)*dx;
integ=integ+A;
end
plot(t,integ);
syms x f(x)
f(x)=-0.073*(x^2)+6.1802*(x);
truearea=int(f(x),x,0,60);
relative_err_frac=((integ-truearea)/truearea)*100;
relative_err=double(relative_err_frac);
if relative_err>0.06
print('ERROR, RELATIVE ERROR TOO HIGH, PLEASE RE INPUT VALUES');
end
Accepted Answer
More Answers (0)
Categories
Find more on Graph and Network Algorithms 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!
