Solving Numerical Differentiation Problem using Scilab Programming

Published: 19 January 2023
on channel: Annie GB Teaching Videos
1,013
11

Given f(x)=exp(-x^2), find f'(x).
In this video, solution to differentiation problem using D1 dan D2 formula and the best estimation using extrapolation.

The computation is shown using Scilab.
I recorded this video during my lecture so you can hear me speaking Bahasa Melayu and English.

The full code is given here.

// This code performs NUMERICAL DIFFERENTIATION

// The name of this function file is f.sci
function y=f(x)
y=exp(-x^2);
endfunction

// The name of this function file is D1.sci
// This is D1 formula
function d1=D1(x,h)
d1=(f(x+h)-f(x))/h;
endfunction

// The name of this function file is D2.sci
// This is D2 formula
function y=D2(x,h)
y=(f(x+h)-f(x-h))/(2*h);
endfunction

x=1;
h=0.2;

disp("The D1 approximation is:")
y1=D1(x,h);
disp(y1);
disp("The D2 approximation is:")
y2=D2(x,h);
disp(y2);

// Extrapolation
T11=2(x,h); //h
T21=D2(x,h/2); // h/2
T31=D2(x,h/4); // h/4
T22=(4*T21-T11)/3;
T32=(4*T31-T21)/3;
T33=(16*T32-T22)/15;
disp("The best approximation using h/2 and h is")
disp(T22)
disp("The best approximation using h/4, h/2 and h is")
disp(T33)

// Exact Solution
function yp=exact(x)
yp=-2*x*exp(-x^2); // EXACT FOR y=exp(-x^2)
endfunction

// Finding the numerical errors
E1=abs(exact(x)-T22);
E2=abs(exact(x)-T33);
disp("The error for T22 is: ")
disp(E1);

disp("The error for T33 is: ")
disp(E2);


On this page of the site you can watch the video online Solving Numerical Differentiation Problem using Scilab Programming with a duration of hours minute second in good quality, which was uploaded by the user Annie GB Teaching Videos 19 January 2023, share the link with friends and acquaintances, this video has already been watched 1,013 times on youtube and it was liked by 11 viewers. Enjoy your viewing!