Gradient value vs. Difference method for higher order of accuracy.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello. I am working on a function that will output the jerk of a specified amount of values within a set of 41 data points for acceleration and time. The first step was to use the gradient function to differentiate the data directly, which I am assuming is correct. However the second step, it is asking to use the the forward difference method for the first two times, and the backwards difference for the last two times with o(h^2), for the rest of the times, the central difference method is to be used with o(h^4). I am getting the same values for all of my data points using each respective method. I am assuming there is an error with my loop or my equation being used, I appreciate the help.
function [method1, method2] = jerk(n)
time=0:0.5:20;
acceleration=[1.1598 0.4475 -0.4118 -0.8763 -1.1162 -1.3032 -1.0846 -0.9286 -0.6847 -0.3565...
0.1492 0.3196 0.4174 0.6239 0.3741 0.4941 0.3753 0.1869 -0.0604 -0.0509...
-0.2230 -0.3186 -0.3044 -0.0780 -0.2808 -0.1727 -0.1700 -0.0001 -0.0872 0.2039...
0.0036 -0.0320 0.0162 0.0378 -0.0943 0.1494 -0.0698 -0.0941 -0.1715 -0.1009 -0.1712];
x=time;
y=x;
z=acceleration(1:n);
L=length(z);
M1=gradient(z,x)';
delq=diff(x(1:2));
G=0;
G=0;
G=0;
D=1;
for D=1:n
for D=1:2
G(D)=(-(acceleration(D)+2*delq)+4*acceleration(D)+delq-3*acceleration(D))/(2*delq);
end
for D=L-1:L
G(D)=(3*acceleration(D)-4*acceleration(D)-delq+acceleration(D)-2*delq)/(2*delq);
end
for D=3:L-2
G(D)=(-(acceleration(D)+2*delq)+8*acceleration(D)+delq-(8*acceleration(D)-delq)+acceleration(D)-2*delq)/(12*delq);
end
end
method1=M1;
method2=[G]';
D=D+1;
jerk=[method1,method2];
end
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!