Test  Status  Code Input and Output 

1  Pass 
% Firstorder forward difference for the first derivative
n = 1;
terms = [1 0];
coeff_correct = [1 1];
errOrder_correct = 1;
errCoeff_correct = 1/2;
[coeff,errOrder,errCoeff] = FDderiv(n,terms);
assert(all(abs(coeffcoeff_correct) < 1e6))
assert(isequal(errOrder,errOrder_correct))
assert(abs((errCoefferrCoeff_correct)/errCoeff_correct) < 1e4)

2  Pass 
% Firstorder backward difference for the first derivative
n = 1;
terms = [0 1];
coeff_correct = [1 1];
errOrder_correct = 1;
errCoeff_correct = 1/2;
[coeff,errOrder,errCoeff] = FDderiv(n,terms);
assert(all(abs(coeffcoeff_correct) < 1e6))
assert(isequal(errOrder,errOrder_correct))
assert(abs((errCoefferrCoeff_correct)/errCoeff_correct) < 1e4)

3  Pass 
% Secondorder centered difference for the first derivative
n = 1;
terms = [1 1];
coeff_correct = [1/2 1/2];
errOrder_correct = 2;
errCoeff_correct = 1/6;
[coeff,errOrder,errCoeff] = FDderiv(n,terms);
assert(all(abs(coeffcoeff_correct) < 1e6))
assert(isequal(errOrder,errOrder_correct))
assert(abs((errCoefferrCoeff_correct)/errCoeff_correct) < 1e4)

4  Pass 
% Secondorder forward difference for the first derivative
n = 1;
terms = [2 1 0];
coeff_correct = [1/2 2 3/2];
errOrder_correct = 2;
errCoeff_correct = 1/3;
[coeff,errOrder,errCoeff] = FDderiv(n,terms);
assert(all(abs(coeffcoeff_correct) < 1e6))
assert(isequal(errOrder,errOrder_correct))
assert(abs((errCoefferrCoeff_correct)/errCoeff_correct) < 1e4)

5  Pass 
% Secondorder backward difference for the first derivative
n = 1;
terms = [0 1 2];
coeff_correct = [3/2 2 1/2];
errOrder_correct = 2;
errCoeff_correct = 1/3;
[coeff,errOrder,errCoeff] = FDderiv(n,terms);
assert(all(abs(coeffcoeff_correct) < 1e6))
assert(isequal(errOrder,errOrder_correct))
assert(abs((errCoefferrCoeff_correct)/errCoeff_correct) < 1e4)

6  Pass 
% Fourthorder centered difference for the first derivative
n = 1;
terms = [2 1 0 1 2];
coeff_correct = [1 8 0 8 1]/12
errOrder_correct = 4;
errCoeff_correct = 1/30;
[coeff,errOrder,errCoeff] = FDderiv(n,terms);
assert(all(abs(coeffcoeff_correct) < 1e6))
assert(isequal(errOrder,errOrder_correct))
assert(abs((errCoefferrCoeff_correct)/errCoeff_correct) < 1e4)
coeff_correct =
0.0833 0.6667 0 0.6667 0.0833

7  Pass 
% Secondorder centered difference for the second derivative
n = 2;
terms = [1 0 1];
coeff_correct = [1 2 1];
errOrder_correct = 2;
errCoeff_correct = 1/12;
[coeff,errOrder,errCoeff] = FDderiv(n,terms);
assert(all(abs(coeffcoeff_correct) < 1e6))
assert(isequal(errOrder,errOrder_correct))
assert(abs((errCoefferrCoeff_correct)/errCoeff_correct) < 1e4)

8  Pass 
% Fourthorder centered difference for the second derivative
n = 2;
terms = [2 1 0 1 2];
coeff_correct = [1 16 30 16 1]/12;
errOrder_correct = 4;
errCoeff_correct = 1/90;
[coeff,errOrder,errCoeff] = FDderiv(n,terms);
assert(all(abs(coeffcoeff_correct) < 1e6))
assert(isequal(errOrder,errOrder_correct))
assert(abs((errCoefferrCoeff_correct)/errCoeff_correct) < 1e4)

9  Pass 
% Secondorder centered difference for the third derivative
n = 3;
terms = [2 1 0 1 2];
coeff_correct = [1/2 1 0 1 1/2];
errOrder_correct = 2;
errCoeff_correct = 1/4;
[coeff,errOrder,errCoeff] = FDderiv(n,terms);
assert(all(abs(coeffcoeff_correct) < 1e6))
assert(isequal(errOrder,errOrder_correct))
assert(abs((errCoefferrCoeff_correct)/errCoeff_correct) < 1e4)

10  Pass 
% Secondorder centered difference for the fourth derivative
n = 4;
terms = [2 1 0 1 2];
coeff_correct = [1 4 6 4 1];
errOrder_correct = 2;
errCoeff_correct = 1/6;
[coeff,errOrder,errCoeff] = FDderiv(n,terms);
assert(all(abs(coeffcoeff_correct) < 1e6))
assert(isequal(errOrder,errOrder_correct))
assert(abs((errCoefferrCoeff_correct)/errCoeff_correct) < 1e4)

619 Solvers
14878 Solvers
221 Solvers
592 Solvers
119 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!