Embed presentation
Download to read offline
![function[dx]=finitediff(x,y)
%it executes forward,backward and central diffrence at two points%
x=[2 3 4];
y=[8 27 64];
n=length(x);
dx(1)=(y(2)-y(1))/(x(2)-x(1));
for i=2:n-1
dx(i)=(y(i+1)-y(i-1))/(x(i+1)-x(i-1));
end
dx(n)=(y(n)-y(n-1))/(x(n)-x(n-1));
-------------
Taimoor Gondal](https://image.slidesharecdn.com/finitedifference-180219135213/75/Finite-difference-Matlab-Code-1-2048.jpg)

This MATLAB code uses finite difference methods to calculate the derivative of a function at discrete points. It takes in input vectors x and y, representing the independent and dependent variables. It then calculates the derivative at each point using forward, backward, and central difference formulas, storing the results in an output vector dx.
![function[dx]=finitediff(x,y)
%it executes forward,backward and central diffrence at two points%
x=[2 3 4];
y=[8 27 64];
n=length(x);
dx(1)=(y(2)-y(1))/(x(2)-x(1));
for i=2:n-1
dx(i)=(y(i+1)-y(i-1))/(x(i+1)-x(i-1));
end
dx(n)=(y(n)-y(n-1))/(x(n)-x(n-1));
-------------
Taimoor Gondal](https://image.slidesharecdn.com/finitedifference-180219135213/75/Finite-difference-Matlab-Code-1-2048.jpg)