I'm working on a project that calculates the derivative of the speed and the integral of the acceleration. my problem is that I have a lot of acceleration points and speed over time and I can not find the right program for that.
example:
So dv/dt = (v2-v1)/(t2-t1) but I don't know how to declare multiple variables for v1 v2 t1 t2
function a=acc(v1,v2,t1,t2)
a= (v2-v1)/(t2-t1)
endfunction
v1=
v2=
t1=
t2=
disp(acc(v1,v2,t1,t2),'acc = ')
and the same for the integral of (dv/dt)*dt
please help me guys
V(1:5) = linspace(0,40,5);
V(6:10) = 40;
V(11:17) = linspace(40,20,7);
Acc = diff(V);
First we populate a array V
with your values for the speed.
Then we create an array Acc
with the acceleration a each seconds with diff
since there's only 1s between two values of V.
Another solution based on what you wrote
function a=acc_2(v1,v2,t1,t2)
a= (v2-v1)./(t2-t1) // since v,t are vectors, we need './' and not '/' !
endfunction
V(1:5) = linspace(0,40,5);
V(6:10) = 40;
V(11:17) = linspace(40,20,7);
v1 = V(1:$-1);
v2 = V(2:$);
t1 = 1:length(V)-1;
t2 = 2:length(V);
Acc_2 = acc_2(v1,v2,t1,t2)
And if you want to have h(x) = int_t0^x dv/dt dt
then use cumsum
H = cumsum(Acc)