All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
DERIVING THE 4TH ORDER APPROXIMATION OF THE SECOND-ORDER DERIVATIVE USING CENTRAL DIFFERENCE AND SKEWED DIFFERENCE SCHEMES. COMPARING THE MENTIONED SCHEMES FOR ABSOLUTE ERROR IN MATLAB. Infer the accompanying fourth request estimate of the second-request subordinate utilizing:- central difference Skewed right-sided…
Gokul Krishnan R S
updated on 09 Jul 2022
DERIVING THE 4TH ORDER APPROXIMATION OF THE SECOND-ORDER DERIVATIVE USING CENTRAL DIFFERENCE AND SKEWED DIFFERENCE SCHEMES. COMPARING THE MENTIONED SCHEMES FOR ABSOLUTE ERROR IN MATLAB.
Infer the accompanying fourth request estimate of the second-request subordinate utilizing:-
Additionally, demonstrate that skewed plans are fourth-request precise.
Compose a program in Matlab to assess the second-order subordinate of the logical capability exp(x)*cos(x) and contrast it and the 3 mathematical approximations that you have determined.
*Give a plot that looks at the outright blunder between the previously mentioned plans
*Depict why a skewed plan is helpful? How might a skewed plan at any point respond that a CD plan mightn't?
Derivation of the 4th order approximation of the Second-Order Derivative
Using the Central Difference method:
we’re deriving using central difference; our numerical stencil will look like this
Here, we're figuring fourth order estimation at point (i), where we take data from the four-point encompassing (i); for example we will take two focuses on the left of (i) and two focuses on the right of (i). Leave those focuses alone (i-2), (i-1), (i+1), and (i+2) and the distance between every one of them is (Δx).
Our mathematical stencil will look like as displayed in the above figure. Based on the above stencil our hypothesis equation will be:-
∂^(2)u/∂x^(2)=af(i-2)+bf(i-1)+cf(i)+df(i+1)+df(i+2)
In order to find the values of coefficient (a,b,c,d,e),we’re going to use the Taylor table method. Writing Taylor series expansion for each term of equation (1) as
By arranging the above Taylor series expansions in Taylor table; we get:-
|
f(i) |
∆xf(i) |
∆x^2f’’(i) |
∆x^3f’’’(i) |
∆x^4f’’’’(i) |
∆x^5f’’’’’(i) |
∆x^6f’’’’’’(i) |
(a)f(i-2) |
a |
-2a |
4a/2 |
-8a/6 |
16a/24 |
-32a/120 |
64a/240 |
(b)f(i-1) |
b |
-b |
b/2 |
-b/6 |
b/24 |
-b/120 |
b/240 |
(c)f(i) |
c |
0 |
0 |
0 |
0 |
0 |
0 |
(d)f(i+1) |
d |
D |
d/2 |
d/2 |
d/24 |
d/120 |
d/240 |
(e)f(i+2) |
E |
2e |
4e/2 |
8e/6 |
16e/24 |
-32e/120 |
64e/240 |
∑(a)f(i-2) (b)f(i-1) (c)f(i) (d)f(i+1) (e)f(i+2) |
0 |
0 |
1 |
0 |
0 |
? |
? |
Note: Only for the initial five terms we accept our speculation. That is the reason we can't say regarding the last two terms.
Here we have five questions, in this way, we need to settle five conditions and get values of coefficients (a,b,c,d,e). We will frame these conditions by adding terms for the singular segments. The summation of coefficients of 'f''(i) is equivalent to 1, and f(I),f′(I),f′'(I),f′''(I),f′'''(I) are equivalent to 0; since we need to ascertain the second-request subsidiary,f′'(I).
Therefore, the five equations are
a+b+c+d+e=0……….. (I)
−2a−b+0+d+2e=0……….. (II)
2a+b/2+0+d/2+2e=1……….. (III)
−8a/6−b/6+0+d/6+8e/6=0……….. (IV)
16a/24+b/24+0+d/24+16e/24=0 ……….. (V)
To get the solution of the above equations, we have to solve the above equations in matrix form; AX=B.
Note: Only for the initial five terms we accept our speculation. That is the reason we can't say regarding the last two terms.
After solving the above the coefficients obtained are
a=-0.83333;
b=1.333333;
c=-2.500000;
d=1.333333;
e=-0.833333;
Here a=e and b=d.
Now, on dividing both side of the hypothesis equation (1) by (Δx^2); we get:
∂^2u/∂x^2 = (−0.083333)f(i−2)+(1.333333)f(i−1)+(−2.500000)f(i)+(1.333333)f(i+1)+(−0.083333)f(i+2)/(Δx^2).
Now, from our Taylor table
∂^2u/(∂x^2)=(a+b+c++d+e)f(i)+(−2a−b+0+d+2e)f′(i)Δx+(2a+1/2b+0+1/2d+2e)f′'(i)Δx^2+(−8/6a−1/6b+0+1/6d+8/6e)f′''(i)Δx^3+(16/24a+1/24b+0+1/24d+16/24e)f′'''(i)Δx^4+(−32/120a−1/120b+0+1/120d+32/120e)f′''''(i)Δx^5+(64/240a+1/240b+0+1/240d+64/240e)f′'''''(i)Δx^6
To get second-order derivative the coefficient of f''(i)has to be 1. And as we want approximation for the second-order derivative, so, the term f(i),f′(i),f′''(i),f′'''(i) will have to ignore or set to ‘0’ in the above equation. On substituting the values of (I), (II), (IV), and (V) in the above equation; we’ll get:
∂^2u/(∂x^2)=(2a+1/2b+0+1/2d+2e)f′'(i)Δx^2+(−32/120a−1/120b+0+1/120d+32/120e)f′''''(i)Δx^5+(64/240a+1/240b+0+1/240d+64/240e)f′'''''(i)Δx^6
On dividing the above equation by (Δx^2), we get:
∂^2u/(∂x^2)=(2a+1/2b+0+1/2d+2e)f′'(i)+(64/240a+1/240b+0+1/240d+64/240e)f′'''''(i)Δx^4
In the above equation, the term Δx^4 denotes the truncation error. Here, we can see that the order of the truncation error; [O(Δx^4)] is ‘4’. Since we know that the order of approximation is defined by the truncation error term. Therefore, we can say that our central difference scheme is 4th order accurate.
After putting the value of (a,b,c,d,e) in the above equation, the final equation looks like this:
∂^2u/(∂x^2)=(2(−0.083333)+1.3333332+1.3333332+2(0.083333))f′'(i)+(64240(−0.083333)+1.333333240+1.333333240+64240(0.083333))f′'''''(i)Δx^4
Using Skewed Right-Sided Difference:
To derive 4th order skewed right-sided difference at point (i) of function. Since we’re using the skewed right-sided method, here we have to define five points on the right of (i). Let those points be (i+1), (i+2), (i+3), (i+4), and (i+5); with a spacing of Δx each.
The numerical stencil will look like this:
According to the above stencil, our hypothesis equation will be:
∂^2u/(∂x)^2=af(i)+bf(i+1)+cf(i+2)+df(i+3)+ef(i+4)+gf(i+5)
In order to find the values of coefficients
(a,b,c,d,e,g), we’re going to use the Taylor table method.
Writing Taylor series expansion for each term of equation (1) as:-
(a)f(i)=af(i)
(b)f(i+1)=(b)f(i)+((b)f′(i)(Δx))/1!+((b)f′'(i)(Δx)^2)/2!+((b)f′''(i)(Δx)^3)/3!+((b)f′'''(i)(Δx)^4/4!+((b)f′'''(i)(Δx)^5)/5!+((b)f′'''''(i)(Δx)^6)/6!+⋯
(c)f(i+2)=(c)f(i)+((c)f′(i)(2Δx))/1!+((c)f′'(i)(2Δx)^2)/2!+((c)f′''(i)(2Δx)^3)/3!+((c)f′'''(i)(2Δx)^4)/4!+((c)f′''''(i)(2Δx)^5)/5!+((c)f′'''''(i)(2Δx)^6)/6!+⋯
(d)f(i+3)=(d)f(i)+((d)f′(i)(3Δx))1!+((d)f′'(i)(3Δx)^2)/2!+((d)f′''(i)(3Δx)^3)/3!+((d)f′'''(i)(3Δx)^4)/4!+((d)f′''''(i)(3Δx)^5)/5!+((d)f′'''''(i)(3Δx)^6)/6!+⋯
(e)f(i+4)=(e)f(i)+((e)f′(i)(4Δx))1!+((e)f′'(i)(4Δx)^2)/2!+((e)f′''(i)(4Δx)^3)/3!+((e)f′'''(i)(4Δx)^4)/4!+((e)f′''''(i)(4Δx)^5)/5!+((e)f′'''''(i)(4Δx)^6)/6!+⋯
(g)f(i+5)=(g)f(i)+((g)f′(i)(5Δx))/1!+((g)f′'(i)(5Δx)^2)/2!+((g)f′''(i)(5Δx)^3)/3!+((g)f′'''(i)(5Δx)^4)/4!+((g)f′''''(i)(5Δx)^5)/5!+((g)f′'''''(i)(5Δx)^6)/6!+⋯
By arranging the above Taylor series expansions in Taylor table; we get:-
|
f(i) |
∆xf(i) |
∆x^2f’’(i) |
∆x^3f’’’(i) |
∆x^4f’’’’(i) |
∆x^5f’’’’’(i) |
∆x^6f’’’’’’(i) |
(a)f(i) |
a |
0 |
0 |
0 |
0 |
0 |
0 |
(b)f(i+1) |
b |
b |
b/2 |
b/6 |
b/24 |
b/120 |
b/720 |
(c)f(i+2) |
c |
2c |
4c/2 |
8c/6 |
16c/24 |
32c/120 |
64c/720 |
(d)f(i+3) |
d |
3d |
9d/2 |
27d/6 |
81d/24 |
243d/120 |
729d/720 |
(e)f(i+4) |
e |
4e |
16e/2 |
64e/6 |
256e/24 |
1024e/120 |
4096e/7230 |
(g)f(i+5) |
g |
5g |
25g/2 |
125g/2 |
625g/24 |
3125g/120 |
15625g/720 |
∑(a)f(i) (b)f(i+1) (c)f(i+2) (d)f(i+3) (e)f(i+4) (g)f(i+5) |
0 |
0 |
1 |
0 |
0 |
0 |
? |
Only for the first six terms, we assume our hypothesis. That’s why we can’t say about the last term.
Here we have six unknowns, so, we have to solve six equations and get values of coefficients (a,b,c,d,e,g).(a,b,c,d,e,g). We are going to form these equations by adding terms for the individual columns. The summation of coefficients of f′'(i)f′′(i) is equal to 1, and f(i),f′(i),f′'(i),f′''(i),f′'''(i),f'''''(i)f(i),f′(i),f′′(i),f′′′(i),f′′′′(i),f′′′′′(i) is equal to 0; because we want to calculate the second-order derivative, f''(i).
Therefore, the six equations are:-
a+b+c+d+e+g=0 ……….. (I)
0+b+2c+3d+4e+5g=0……….. (II)
0+b/2+2c+9d/2+8e+25g/2=0……….. (III)
0+b/6+8c/6+27d/6+64e/6+125g/6=0 ……….. (IV)
0+b/24+16c/24+81d/24+256e/24+625g/24=0 ……….. (V)
0+b/120+32c/120+243d/120+1024e/120+3125g/120= ……….. (VI)
To get the solution of the above equations, we have to solve the above equations in matrix form; AX=B.
After solving the above matrix, we get the values of all the coefficients as:-
a=3.75000
b=−12.83333
c=17.83333
d=-13.00000
e=5.08333
g=-0.83333
Now, dividing both side of hypothesis equation (1) by (Δx2); we get:
∂^2u/∂x^2=(af(i)+bf(i+1)+cf(i+2)+df(i+3)+ef(i+4)+gf(i+5)(Δx2)∂2u∂x2=af(i)+bf(i+1)+cf(i+2)+df(i+3)+ef(i+4)+gf(i+5))/(∆x^2)
After putting the values of all the coefficients (a,b,c,d,e,g) in the above equation, we will get the fourth-order skewed right-sided difference approximation for second-order derivative.
∂^2u/∂x^2=((3.75000)f(i)+(−12.83333)f(i+1)+(17.83333)f(i+2)+(−13.00000)f(i+3)+(5.083333)f(i+4)+(−0.83333)f(i+5)(Δx2)∂2u∂x2=(3.75000)f(i)+(-12.83333)f(i+1)+(17.83333)f(i+2)+(-13.00000)f(i+3)+(5.083333)f(i+4)+(-0.83333)f(i+5))/(∆x^2)
Now, from Taylor table:-
∂^2u/∂x^2=(a+b+c+d+e+g)f(i)+(0+b+2c+3d+4e+5g)f′(i)Δx+(0+b/2+4c/2+9d/2+16e/2+25g/2)f′'(i)Δx^2+(0+b/6+8c/6+27d/6+64e/6+125g/6)f′''(i)Δx^3+(0+b/24+16c/24+81d/24+256e/24+625g/24)f′'''(i)Δx^4+(0+b/120+32c/120+243d/120+1024e/120+3125g/120)f′''''(i)Δx^5+(0+b/720+64c/720+729d/720+4096e/720+15625g/720)f′'''''(i)Δx^6
To get second-order derivative the coefficient of f''(i) has to be 1. And as we want approximation for the second-order derivative, so, the term f(i),f′(i),f′''(i),f′'''(i),f'''''(i) will have to ignore or set to '0' in the above equation. On substituting the values of (I), (II), (IV), (V), and (VI) in the above equation; we’ll get:
∂^2u/∂x^2=(0+b/2+4c/2+9d/2+16e/2+25g/2)f′'(i)Δx^2+(0+b/720+64c/720+729d/720+4096e/720+15625g/720)f′'''''(i)Δx^6
On dividing the above equation by (∆x2), we get:-
∂^2u/∂x^2=(b2+2c+9d2+8e+25g2)f′'(i)+(b/720+64c/720+729d/720+4096e/720+15625g/720)f′'''''(i)Δx^4
As we discussed earlier also, the Δx4∆x4 denotes the truncation error. Here we can see that order of the truncation error; [O(Δx4)] is '4'. Since, we know that the order of approximation is defined by the truncation error term. Therefore, we can say that our skewed right-sided difference scheme is of 4th order accurate.
After putting the values of (a,b,c,d,e,g) in the above equation, the final equation looks like this:-
∂^2u/∂x2=(−12.83333/2+2(17.83333)+((9(−13.00000)/2))+8(5.08333)+((25(−0.08333)/2))f′'(i)+(−12.83333/720+(64(17.83333)/720)+(729(−13.00000)/720)+(4096(5.08333)/720)+(15625(−0.08333)/720)f′'''''(i)Δx^4
Using Skewed Left-Sided Difference:
To derive 4th order skewed left-sided difference at point (i) of function. Since we’re using the skewed left-sided method, here we have to define five points on the left of (i). Let those points be (i-1), (i-2), (i-3), (i-4), and (i-5); with a spacing of Δx each.
The numerical stencil will look like this:
According to the above stencil, our hypothesis equation will be:
∂^2u/∂x^2=af(i−5)+bf(i−4)+cf(i−3)+df(i−2)+ef(i−1)+gf(i)
To find the values of coefficients (a,b,c,d,e,g) we’re going to use the Taylor table method.
Writing Taylor series expansion for each term of equation (1) as:-
(a)f(i−5)=(a)f(i)−((a)f′(i)(5Δx))/(1!)+((a)f′'(i)(5Δx)^2)/(2!)−((a)f′''(i)(5Δx)^3)/(3!)+((a)f′'''(i)(5Δx)^4)/(4!)−((a)f′''''(i)(5Δx)^5)/(5!)+((a)f′'''''(i)(5Δx)^6)/(6!)+⋯
(b)f(i−4)=(b)f(i)−((b)f′(i)(4Δx))(1!)+((b)f′'(i)(4Δx)^2)/(2!)−((b)f′''(i)(4Δx)^3)/(3!)+((b)f′'''(i)(4Δx)^4)/(4!)−((b)f′''''(i)(4Δx)^5)/(5!)+((b)f′'''''(i)(Δx)^6)/(6!)+⋯
(c)f(i−3)=(c)f(i)−((c)f′(i)(3Δx))(1!)+((c)f′'(i)(3Δx)^2)/(2!)−((c)f′''(i)(3Δx)^3)/(3!)+((c)f′'''(i)(3Δx)^4)/(4!)−((c)f′''''(i)(3Δx)^5)/(5!)+((c)f′'''''(i)(3Δx)^6)/(6!)+⋯
(d)f(i−2)=(d)f(i)−((d)f′(i)(2Δx))/(1!)+((d)f′'(i)(2Δx)^2)/(2!)−((d)f′''(i)(2Δx)^3)/(3!)+((d)f′'''(i)(2Δx)^4)/(4!)−((d)f′''''(i)(2Δx)^5)/(5!)+((d)f′'''''(i)(2Δx)^6)/(6!)+⋯
(e)f(i−1)=(e)f(i)−((e)f′(i)(Δx))/(1!)+((e)f′'(i)(Δx)^2)/(2!)−((e)f′''(i)(Δx)^3)/(3!)+((e)f′'''(i)(Δx)^4)/(4!)−((e)f′''''(i)(Δx)^5)/(5!)+((e)f′'''''(i)(Δx)^6)/(6!)+⋯
(g)f(i)=(g)f(i)
By arranging the above Taylor series expansions in Taylor table; we get:-
|
f(i) |
∆xf(i) |
∆x^2f’’(i) |
∆x^3f’’’(i) |
∆x^4f’’’’(i) |
∆x^5f’’’’’(i) |
∆x^6f’’’’’’(i) |
(a)f(i-5) |
a |
-5a |
25a/2 |
-1252/6 |
625a/24 |
-3125a/120 |
15625a/720 |
(b)f(i-4) |
b |
-4b |
8b |
-64b/6 |
256b/24 |
-1024b/120 |
4096b/720 |
(c)f(i-3) |
c |
-3c |
9c/2 |
-27c/2 |
81c/24 |
-243c/120 |
729c/120 |
(d)f(i-2) |
d |
-2d |
2d |
-8d/6 |
16d/24 |
-32d/120 |
64d/720 |
(e)f(i-1) |
e |
-e |
e/2 |
-e/6 |
e/24 |
-3/120 |
e/720 |
(g)f(i) |
g |
0 |
0 |
0 |
0 |
0 |
0 |
∑ a)f(i-5) (b)f(i-4) (c)f(i-3) (d)f(i-2) (e)f(i-1) (g)f(i) |
0 |
0 |
1 |
0 |
0 |
0 |
? |
Only for the first six terms, we assume our hypothesis. That’s why we can’t say about the last term.
Here we have six unknowns, so, we have to solve six equations and get values of coefficients (a,b,c,d,e,g). We are going to form these equations by adding terms for the individual columns. The summation of coefficients of f′'(i) is equal to 1, and f(i),f′(i),f′'(i),f′''(i),f′'''(i),f'''''(i) is equal to 0; because we want to calculate the second-order derivative, f''(i).
Therefore, the six equations are:-
a+b+c+d+e+g=0 ……….. (I)
-5a-4b-3c-2d-e+0=0 ……….. (II)
125a/2+8b+9c/2+2d+e/2+0=1 ……….. (III)
625a/24+256b/24+81c/24+16c/24+e/24+0=0 ……….. (V)
-3125a/120-1024b/120-243c/120-32d/120-e/120+0=0 ……….. (VI)
To get the solution of the above equations, we have to solve the above equations in matrix form; AX=B.
After solving the above matrix, we get the values of all the coefficients as:-
a=−0.83333
b=5.08333
c=-13.00000
d=17.83333
e=-12.83333
g=3.75000
Now, dividing both side of the hypothesis equation (1) by (Δx2); we get:
∂^2u/∂x^2=(af(i−5)+bf(i−4)+cf(i−3)+df(i−2)+ef(i−1)+gf(i))/(∆x2)
After putting the values of all the coefficients (a,b,c,d,e,g) in the above equation, we will get the fourth-order skewed left-sided difference approximation for second-order derivative.
∂^2u/∂x^2=((−0.83333)f(i−5)+(5.08333)f(i−4)+(−13.00000)f(i−3)+(17.83333)f(i−2)+(−12.83333)f(i−1)+(3.75000)f(i))/(Δx^2)
Now, from our Taylor table:-
∂^2u/∂x^2=(a+b+c++d+e+g)f(i)+(−5a−4b−3c−2d−e+0)f′(i)Δx+((25a/2+8b+9c/2+2d+e/2+0))f′'(i)Δx^2+((−125a/6−64b/6−27c/6−8d/6−e/6+0))f′''(i)Δx^3+((625a/24+256b/ 24+81c/24+16c/24+e/24+0))f′'''(i)Δx4+((−3125a/120−1024b/120−243c/120−32d/120−e/120+0))f′''''(i)Δx5+((15625a/720+4096b/720+729c/720+64d/720+e/720+0))f′'''''(i)Δx^6
To get second-order derivative the coefficient of f''(i) has to be 1. And as we want approximation for the second-order derivative, so, the term f(i),f′(i),f′''(i),f′'''(i),f'''''(i),f′′′′′(i) will have to ignore or set to 0 in the above equation. On substituting the values of (I), (II), (IV), (V), and (VI) in the above equation; we’ll get:
∂^2u/∂x^2=(25a/2+8b+9c/2+2d+e/2+0)f′'(i)Δx^2+(15625a/720+4096b/720+729c/720+64d/720+e/720+0)f′'''''(i)Δx^6
On dividing the above equation byΔx^2; we get:-
∂^2u/∂x^2=(25a/2+8b+9c/2+2d+e/2)f′'(i)+(15625a/720+4096b/720+729c/720+64d/720+e/720)f′'''''(i)Δx^4
As we discussed earlier also, the Δx4∆x4 denotes the truncation error. Here we can see that order of the truncation error; [O(Δx4)] is ‘4’. Since, we know that the order of approximation is defined by the truncation error term. Therefore, we can say that our skewed left-sided difference scheme is of 4th order accurate.
After putting the values of (a,b,c,d,e,g) in the above equation, the final equation looks like this:-
∂^2u/∂x^2=((25(−0.833333)/2+8(5.08333)+9(−13.00000)/2+2(17.83333)+−12.83333/2)f′'(i)+(15625(−0.08333)/720+4096(5.08333)/720+729(−13.00000)/720+64(17.83333)/ 720+−12.83333/720)f′'''''(i)Δx^4
PROGRAM IN MATLAB TO EVALUATE THE SECOND-ORDER DERIVATIVE OF THE ANALYTICAL FUNCTION AND COMPARE IT WITH THE NUMERICAL APPROXIMATION THAT WE HAVE DERIVED ABOVE
First and foremost we will compose projects to foster capabilities for central, skewed right-sided and skewed left-sided errors at a specific point (x, dx), where dx addresses in the middle of between every node. These functions will assist us with computing errors over the scope of 'dx'. With the assistance of code 'function out' we will make function; which we save in directory and call as per our need in the principal program.
FUNCTION FOR CENTRAL DIFFERENCING
%fourth order approximation of second order derivative using central difference
function central_difference_error=central_difference(x,dx)
%analytical function f(x)=exp(x)*cos(x)
%f''(x)=-2*exp(x)*sin(x)
analytical_derivative=-2*exp(x)*sin(x);
% cofficient values calculated from Taylor table
%matrix multiplication
A=[1 1 1 1 1;-2 -1 0 1 2;2 1/2 0 1/2 2;-8/6 -1/6 0 1/6 8/6;16/24 1/24 0 1/24 16/24]
B=[0;0;1;0;0]
y=inv(A)*B
a=y(1);
b=y(2);
c=y(3);
d=y(4);
e=y(5);
%numerical derivative
%central_differencing=((a*f(x-2*dx))+(b*f(x-dx))+(c*f(x))+(d*f(x+dx))+(e*f(x+2*dx)))/dx^2
central_difference_fourth_order_approx=((a*exp(x-2*dx)*cos(x-2*dx))+(b*exp(x-dx)*cos(x-dx))+(c*exp(x)*cos(x))+(d*exp(x+dx)*cos(x+dx))+(e*exp(x+2*dx)*cos(x+2*dx)))/dx^2;
central_difference_error=abs(central_difference_fourth_order_approx-analytical_derivative);
end
FUNCTION FOR SKEWED RIGHT SIDED DIFFERENCE
%fourth order approximation of second order skewed right sided difference
function skewed_right_side_error=skewed_right_side(x,dx)
%analytical function f(x)=exp(x)*cos(x)
%f''(x)=-2*exp(x)*sin(x)
analytical_derivative=-2*exp(x)*sin(x);
% cofficient values calculated from Taylor table
%matrix multiplication
A=[1 1 1 1 1 1;0 1 2 3 4 5;0 1/2 4/2 9/2 16/2 25/2;0 1/6 8/6 27/6 64/6 125/6;0 1/24 16/24 81/24 256/24 625/24;0 1/120 32/120 243/120 1024/120 3125/120]
B=[0;0;1;0;0;0]
z=inv(A)*B
a=z(1);
b=z(2);
c=z(3);
d=z(4);
e=z(5);
g=z(6);
%numerical derivative
%central_differencing=((a*f(x))+(b*f(x+dx))+(c*f(x+2*dx))+(d*f(x+3*dx))+(e*f(x+4*dx))+(g*f(x+5*dx)))/dx^2
skewed_right_side_fourth_order_approx=((a*exp(x)*cos(x))+(b*exp(x+dx)*cos(x+dx))+(c*exp(x+2*dx)*cos(x+2*dx))+(d*exp(x+3*dx)*cos(x+3*dx))+(e*exp(x+4*dx)*cos(x+4*dx))+(g*exp(x+5*dx)*cos(x+5*dx)))/dx^2;
skewed_right_side_error=abs(skewed_right_side_fourth_order_approx-analytical_derivative);
end
FUNCTION FOR SKEWED LEFT SIDED DIFFERENCE
%fourth order approximation of second order derivative using skewed leftside difference
function skewed_left_side_error=skewed_left_side(x,dx)
%analytical function f(x)=exp(x)*cos(x)
%f''(x)=-2*exp(x)*sin(x)
analytical_derivative=-2*exp(x)*sin(x);
% cofficient values calculated from Taylor table
%matrix multiplication
A=[1 1 1 1 1 1;-5 -4 -3 -2 -1 0;25/2 16/2 9/2 4/2 1/2 0;-125/6 -64/6 -27/6 -8/6 -1/6 0;625/24 256/24 81/24 16/24 1/24 0;-3125/120 -1024/120 -243/120 -32/120 -1/120 0]
B=[0;0;1;0;0;0]
u=inv(A)*B
a=u(1);
b=u(2);
c=u(3);
d=u(4);
e=u(5);
g=u(6);
%numerical derivative
%central_differencing=((a*f(x-5*dx))+(b*f(x-4*dx))+(c*f(x-3*dx))+(d*f(x-2*dx))+(e*f(x-dx))+(g*f(x)))/dx^2
skewed_left_side_fourth_order_approx=((a*exp(x-5*dx)*cos(x-5*dx))+(b*exp(x-4*dx)*cos(x-4*dx))+(c*exp(x-3*dx)*cos(x-3*dx))+(d*exp(x-2*dx)*cos(x-2*dx))+(e*exp(x-dx)*cos(x-dx))+(g*exp(x)*cos(x)))/dx^2;
skewed_left_side_error=abs(skewed_left_side_fourth_order_approx-analytical_derivative);
end
MAIN PROGRAM
%calculating fourt order error of second order derivative
clear all
close all
%inputs
x=pi/3;
dx=linspace(pi/4,pi/40000,100);
%looping
for i=1:length(dx)
central_difference_error(i)=central_difference(x,dx(i));
skewed_right_side_error(i)=skewed_right_side(x,dx(i));
skewed_left_side_error(i)=skewed_left_side(x,dx(i));
end
%plotting
figure(1)
plot(dx,central_difference_error,'marker','x','color','r','linewidth',1)
hold on
plot(dx,skewed_right_side_error,'marker','o','color','g','linewidth',1)
plot(dx,skewed_left_side_error,'marker','*','color','c','linewidth',1)
xlabel('dx')
ylabel('error')
hold off
grid on
legend('Central Difference Error','Skewed Right-Side Error','Skewed Left-Side Error')
figure(2)
loglog(dx,central_difference_error,'marker','x','color','r','linewidth',1)
hold on
loglog(dx,skewed_right_side_error,'marker','o','color','g','linewidth',1)
loglog(dx,skewed_left_side_error,'marker','*','color','c','linewidth',1)
xlabel('range of dx')
ylabel('Truncation Error')
hold off
grid on
legend('Central Difference Error','Skewed Right-Side Error','Skewed Left-Side Error')
title('RANGE OF dx vs error')
CONCLUSION
As seen from the plot, the centrall differencing plan has extremely less error contrasted with different schemes. Subsequently, central differencing is superior to different schemes since it utilizes data from both the sides from the place of thought to give approximative and precise qualities.
As the left and right skewed difference strategies utilizes information just from one side of focal point it gives less approximative and exact qualities about the point.
WHY A SKEWED SCHEME IS USEFUL:
The framework which doesn't contain adequate data on both side of the central point. In such cases we can't utilize central differencing plan so skewed scheme is valuable in such cases.
WHAT CAN A SKEWED SCHEME DO THAT A CD SCHEME CANNOT DO:
CDS can't be utilized at the boundry nodes because of inaccessibility of right and left nodes simultaneously. In such cases the skewedd differencing scheme is utilized.
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Design of backdoor
Aim : To develop the car Backdoor(Tail gate) with the reference of given skin data as per engineering standarad by using NX12 Back Door : The Back door is typically hinged, but sometimes attached by other mechanisms…
22 Oct 2022 06:40 AM IST
Roof Design
INTRODUCTION The roof of a car or other vehicle is the top part of it, which protects passengers or goods from the weather. The roof also protects the passenger from any injury when the car gets crashed or is rolled over or something heavy falls on the roof. OBJECTIVE: …
17 Oct 2022 06:53 AM IST
Fender Design
Objective To design various mounting points on the fender, according to the design parameters. Fender Fender is the US English term for part of an automobile (vehicle body of car) that frames the wheel well (the fender underside). A fender is the part of an automobile which may be a car, motorcycle or any other…
06 Oct 2022 02:51 PM IST
Fender Design - Wheel Arch Challenge
Aim: To calculate the Fender Wheel Arc area , to pass the European standards. Objective: Create the intersection point according to given degree angle. Follow the European standards…
01 Oct 2022 05:17 AM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.