Finite difference table method in numerical analysis
Size: 862.14 KB
Language: en
Added: May 23, 2023
Slides: 10 pages
Slide Content
PRACTICAL Name- Saloni Singhal M.Sc. (Statistics) II-Sem. Roll No: 2046398 Course- MATH-409 L Numerical Analysis Lab Submitted To: Dr. S.C. Pandey 6.1
O BJECTIVE Create an M-file to calculate Forward Difference table. 2. Create an M-file to calculate Backward Difference table
Theory The forward difference , denoted by Δ (delta) , is defined as Δ y = Δ f(x) = f(x + h) - f(x), here h is called the interval of differencing; Δ f(x) is the first order differences. We get the second order differences (denoted by Δ 2 ) when Δ is operated twice on f(x), Thus Δ 2 y = Δ 2 f(x) = Δ [ Δ f(x)] = Δ [f(x + h) - f(x)] = Δ f(x + h) - Δ f(x) = [f(x + 2h) - f(x + h)] - [f(x + h) - f(x)] = f(x + 2h) -2f(x + h) + f(x). Similarly, Δ 3 , Δ 4 , Δ 5 etc. may be calculated We now define a difference operator ∇( nabla ) known as backward difference operator , given by ∇ f( x+h ) = f(x + h) - f(x), Relation between both operators: ∇ f( x+h ) = Δ f(x)
Script File Forward Difference Table x=[0.1,0.15,0.2,0.25,0.3]; y=[0.1003,0.1511,0.2027,0.2553,0.3093]; %y=tan(x) n=5; %row vector will be converted in to colum vector for i =1:n diff(i,1)=y( i ); end %calculation of differences for j=2:n for i =1:n-j+1 diff( i,j )=diff(i+1,j-1)-diff(i,j-1); end end %printing forward difference table fprintf ( '\n*****The forward difference table*****' ); fprintf ( '\n x\t y\t Δ1\t Δ2\t Δ3\t Δ4\t ' ); for i =1:n fprintf ( '\n %.2f' ,x( i )); for j=1:n-i+1 fprintf ( '\t %.4f' ,diff( i,j )); end end
Output >> plot( x,y, 'or ' )
Script File Backward Difference Table delx =1; x=0:delx:4; y=[1,2.7183,7.3891,20.0855,54.5982]; %y=exp(x) n=5; %row vector will be converted in to column vector for i =1:n diff(i,1)=y( i ); end %calculation of differences for j=2:n for i = j:n diff( i,j )=diff(i,j-1)-diff(i-1,j-1); end end %printing backward difference table fprintf ( '\n*****The backward difference table*****' ); fprintf ( '\n x\t y\t\t ∇ 1\t\t ∇ 2\t\t ∇ 3\t\t ∇ 4' ); for i =1:n fprintf ( '\n %d\ t' ,x ( i )); for j=1:i fprintf ( '%.4f\t\ t' ,diff ( i,j )); end
Output >> plot(x, y)
Time Complexity 8 For the given program it is calculated as: For line 7= n since loop For line 12= 4[(n-1)+(n-2)… 1] since 4 operation in nested loop = 2n(n-1) on adding the above dominant value is =O(n 2 ) Big O notation is the most common metric for calculating time complexity. It describes the execution time of a task in relation to the number of steps required to complete it. We calculate the no of operations in respective loops and function. Big ‘O’ notation takes its dominant value
Error Propagation If any entry of the difference table is erroneous, then this error spread over the table in convex manner. The error increases with the order of the differences. It is maximum (in magnitude) along the horizontal line through the erroneous tabulated value. The algebraic sum of errors in any complete column is zero. If at any stage, the differences do not follow a smooth pattern, then there is an error.
Conclusion It is observed from the forward and backward difference tables that for a given table of values both the tables are same. Practically, there are no differences among the values of the tables, but, theoretically they have separate significance in interpolation formulas.