M-Tech 1 Year Cace Lab Computational Lab
M-Tech 1 Year Cace Lab Computational Lab
M-Tech 1 Year Cace Lab Computational Lab
CACE Lab
COMPUTATIONAL LAB
Derivation:
Let x0 be an initial approximation to the root of f(x)=0 then P(x o,f0) i.e.,
where f0 = f(x0) is a point on the curve, there we draw a tangent to the
curve at point P. We approximate the curve at the point M the
neighborhood of the root by the tangent to the curve at the point P.
Then point of intersection of the tangent with the x- axis is taken as the
next approximation to the root. The process is repeated until the required
accuracy is obtained. The equation of the tangent to the curve y=f(x) at
point P(xo,f0) is given by,
Question:
C { A {0 }}( l − x )
C { A }= { A}
l+ £ { A } x { A } ¿
¿
C { A {0 }} x { A } ( 1+ x { A } ) Ɣ 1000 lit
τ=
0.6 C { A { 0}} ( 1− x
= Ɣ {0 }
= 180lit /min
{ A} )
x { A }+ x 2{ A }
= 5.56 (1-xA)
0.6
x 2+ 4.33 x { A } −3.33=0=f ( x )
f ( x {0 } )
x1= x0 – f ' ( x {0 })
here f’(x) = 2xA + 4.33
−0.915
x1 = 0.5 - 6.33 = 0.67167
0.02947
x2 = 0.67167 – 6.35.673343 = 0.66647
−2.639 x 10− 6
x3 = 0.66647 - 5.66294
= 0.66647
∴ xA= 0.66647
MATLAB Code:
x1=x-(f(x)/df(x));
x=x1;
end
sol=x;
fprintf('Approximate Root is %.15f',sol)
a=0.5, b=1;
x=a;
er(5)=0;
for i=1:1:5
x1=x-(f(x)/df(x));
x=x1;
er(i)=x1-sol;
end
plot(er)
xlabel('number of iterations')
ylabel('error')
title('erroe vs number of iterations')
Output:
a = 0.5
Approximate root is 0.6664704
Derivation:
Let the root of the equation f(x)=0 lie in the interval (x k-1, xk) then P(xk-1,
fk-1), Q(xk , fk) are points on the curve f(x) = 0. Drawing the chord joining
the points P & Q taking the chord f(x)=ax+b, the next approximation is
b
given by x = − a
Subtracting
fk - fk-1 = a(xk - xk-1)
a = [fk – fk-1]/[xk – xk-1]
b = fk - axk , the next approximation
b f {k } − a x { k }
xk+1 = − a = − a
x {k } − x { k− 1}
xk+1 = xk –( f {k } − f {k −1 } ¿ ) fk
¿
Description:
At the start of each iteration the required root lies in on interval, whose
length is decreasing. Hence the method converges. The disadvantage is
if the root lies initially in the interval (x 0,x1) the one of the end points is
fixed the end points is fixed for all iterations.
Question:
2 ( 1+0.2 ) s 2
R→ 0.2 –––– O ––––– 1+ 0.025
––––––– 2
s + 11s+ 1
––––––––––––> Y(s)
0.2
Find the roots of the characteristic equation,
2 ( 1+0.2 s ) 2
x
y (s ) 1+ 0.02 s s2 +11 s+1
=
R( s) 0.2 x 2 ( 1+0.2 s ) x 2
1+
(1+ 0.02 s ) ( s2 +11s +1 )
Characteristic equation,
0.2 x 2 (1+0.2 s ) x 2
1+ ( 1+ 0.02 s ) ( s2 +11 s+1 )
=0
0.02s3 + 1.22s2+12.62s+18=0
S3+16s2+631s+90=0
f(-13) = -1 f(-14)=468
1( − 1)
x1 = -13 - − 468+ 1 = 13.0021322
[-13.0021322, -14]
f(a) = -0.04467 f(b) = 468
−0.04467 − 0.9978678
x2 = -13.0021322 - − 468+0.0467 = -13.002227
[-13.002227, -14]
f(a) = -1.9996x10-3 f(b)= 468
−1.9996 x 10 −3(−0.997773)
x3 = -13.002227 - 468+1.9996 x 10 − 3
= -13.00223
∴ x = -13.0022
MATLAB Code:
% False position method
clc;
f=@(x) x^3+(61*(x^2))+(631*x)+90;
a=-13; b=-14;
for i=1:10
x0=a;x1=b;
fprintf('\n hence root lies between (%.4f,%.04f)',a,b);
x2(i)=x0-((x1-x0)/(f(x1)-f(x0)))*f(x0);
if f(x2(i))>0
b=x2(i);
else a=x2(i);
end
fprintf('\n therefore, x2=%.4f\n here, f(x2)=%.4f',x2(i),f(x2(i)))
p=x2(i);
end
for i=1:10
error(i)=p-x2(i);
end
Output:
here the root lies between (-13,-14)
therefore X2 = -13.00
Definition :
Runge kutta formula’s are among the oldest and best understood
schemes in numerical analysis and provide a proper way to solve the
initial value problem of a system of ODE’s.
Derivation :
k1 = f(x,y)
ℎ 1
k2 = f(xi + 2 , yi+ 2 k1h)
ℎ 1
k3 = f(xi + 2 , yi+ 2 k2h)
k4 = f(xi + h , y+ k3h)
1
yi+1 = yi + 6 [k1 + 2k2 + 2k3 +k4] x h
Description :
Question:
MATLAB Code:
x0=input('enter the values of x0');
y0=input('enter the values of y0');
h=input('enter the values of h');
xf=input('enter the values of xf');
x=x0:h:xf;
y1=y0;
rkf=@(x,y) (0.25-(0.3*y));
for i=1:length(x)-1
k1=h*rkf(x(i),y(i));
k2=h*rkf((x(i)+(h/2)),(y(i)+(k1/2)));
k3=h*rkf((x(i)+(h/2)),(y(i)+(k2/2)));
k4=h*rkf((x(i)+h),(y(i)+k3));
y(i+1)=y(i)+((k1+(2*k2)+(2*k3)+k4)/6);
x(i+1)=x(i)+h;
end
disp(x);
disp(y);
disp('rk 4th mehod');
disp('iteration x y');
for i=1:length(x)
fprintf('%d\t %f\t %f\n',i,x(i),y(i));
end
Output:
Definition:
This method is basically used to solve simultaneous linear
equations, done by an elimination process.
Derivation:
[ a21 a 22 a23
a31 a 32 a33 ][ ] [ ]
x2
x3
= b2
b3
By row operations.
a11 a12 a 13 x 1 b'
[ ][ ] [ ]
0 a22 a 23 x 2 = b' '
0 a32 a 33 x 3 b '' '
then finally
a11 a12 a 13 x 1 b'
[ 0 ][ ] [ ]
0 a22 a 23 x 2 = b' '
0 a 33 x 3 b '' '
Description:
Sometimes it fails when anyone of the pivot is zero or a very small
number as the elimination progresses. The element a 332≠0 is called the
third pivot. This system uses upper triangular form.
Question:
Consider a liquid entering into a pipe of length L and diameter D at
a fixed pressure Pi , as shown in the fig. below and the flow distributes
itself into 2 pipes each of lengths L1, L2 and diameters D1, D2 with fixed
exit pressure Pa then determine the velocities of the flowing each pipe.
32 µVL
From laminar flow ∆p= D2
Q=Q1+Q2
VA¿ V 1 A 1+V 2 A2
2 2
Vπ D 2 V 1 π D 1 V 2 π D 2
= +
4 4 4
At function
32 µVL
Pi-P¿ D2
32 µV 1 L1
P-Pa¿ D2 pipe-2
1
32 µV 2 L2
P-Pa¿ D2 pipe-3
2
32 µVL 32 µ V 1 L1
Pi-P+P-Pa¿ D2 + D2
1
32 µVL 32 µ V 1 L1
Pi-Pa¿ D2 + D2
1
2 2 2
D V − D 1 V 1 − D 2 V 2=0
D2 − D21 − D22
[ 32 µL
D2
32 µL
D2
L=5m, L1=4m,
32 µ L1
D
0
2
1
L2=3m
0
32 µ L2
D22
] V
[][ ]
V1
V2
=
0
Pi − P a
Pi − P a
[ 0.4 1.28
0.4 0
0 V
][ ] [ ]
1
0.96 V 2
= 200
200
1 −0.25 −0.25 0
[ 0.4 1.28
0.4 0
0 200
0.96 200
1 −0.25 − 0.25 0
]
R2->R2-0.4R1 R3->R3-0.4R1
[ 0 1.18
0 0
0.1
][ ] [ ]
V 1 = 200
1.0515 V 2 183.05
V2=176.2 m/s V1=132.15 m/s V=77.09 m/s
MATLAB Code:
Output:
Trapezoidal method:
Definition :
The Trapezoidal rule is a numerical method that approximates the
b
Derivation:
The curve y=f ( x ) ; a ≤ x ≤ b be approximated by the line joining the point P,
Q
I =∫ f ( x ) dx=∫ f ( x) dx
a x0
x1 x1
¿ f ( x 0 ) ∫ dx +
0x
1
ℎ [∫
x0
]
( x − x 0 ) dx ∆ f 0
1 1 x
ℎ 2 x0 |{
¿ ( x 1 − x0 ) f ( x0 ) + ∗ ( x − x 0 )2 1 ∆ f 0
ℎ
¿ ℎ ∗ f ( x0 )+ [ f ( x1 ) − f x0¿ ]
2
ℎ
¿ [ f (x 1)+ f ( x 0) ]
2
b
∫ f ( x ) dx= b −2 a [ f ( b ) +f (a)]
a
Description :
Basically, the right hand side of the trapezium rule is the area of
the trapezoid with width b-a, and ordinates f ( a ) , f ( b ) which is an
approximation to the area under the curve y=f ( x )
Question:
A gaseous reactor A, decomposes as A->3R and -r a=0.6CA in
batch reactor with conversion XA=0.925 feed as 50% feed and 50% inert
feed and CA0¿ 300 m. mol /lit to a lm3 reactor . Calculate the volumetric flow
rate of the initial feed .
XA
V T d XA
= =∫ - l A =0.6 C A
F A 0 C A 0 0 −l A
0.925
1000lit ( 1+ X A )
=∫ d XA
γ0 0 ( 0.6 ( 1− X A ) )
0.925
0.6 1+ X A
1000 ∗ =∫ d XA
γ0 0 1− X A
MATLAB Code:
clc
clear all
close all
f=@(x) ((1+x)/(1-x));
x0=input('enter x0');
xn=input('enter final value xn');
N=input('enter total num of steps');
h=((xn-x0)/N);
area=0;
while (x0<xn)
area=area+(h/2)*(f(x0)+f(x0+h));
x0=x0+h;
end
fprintf('area is %f',area);
Output:
Enter x0 0
Enter final value xn 0.925
Enter no of steps 5
Area is 5.02249
Definition:
Derivation:
Taking the equations as,
a 11 x 1=b 1 − ( a12 x 2 +a13 x3 )
a 22 x2 =b2 − ( a 21 x 1+ a23 x 3 )
a 33 x 3=b3 − ( a31 x 1+ a32 x 2 )
From this we take the Jacobi Iteration as
1
x k+1
1 = [ b1 − ( a12 x2k + a13 x k3 ) ]
a 11
1
x k+1
2 = [b2 − ( a21 x k1 +a23 x3k )
]
a 22
1
x k+1
3 = [b − ( a31 x k1 +a 32 x2k ) where
] k=0,1,2,…..
a 33 3
Description:
Here, we replace the complete vector xk, in the right hand side of
the above equation at the end of each iteration. This method is also
called the method of simultaneous displacement.
Question:
An ageous solution of pyridine containing 27% by wt of pyridine and
75% water is to be extracted with chlorobenzene. The feed and solvent
are mixed well in a batch extractor then allowed for phase separation.
The extract phase contains 11% pyridine 88% chlorobenzene 1% water
by weight raffinate phase contains 6% pyridine, 94% water by weight
.Calculate the quantities of 2 phases.
Feed +solvent= raffinate phase +extract phase
100+z=x +y (1)
Material balance for pyridine
100*0.27+0=x*0.11+y*0.06
0.11x+0.06y=27 (2)
Material balance for water
100*0.73+0=x*0.01+y*0.94
0.01x+0.94y=73 (3)
The simultaneous linear equations are
x +y-z=100
0.11x+0.06y=27
0.01x+0.94y=73
From this z=x+y-100
0.06 x
x=27 −
0.11
0.01 x
y=73 −
0.94
1st Iteration:
Initially x0=0(say)
X1=27/0.11 =245.45
Y1= (73-0.01(245.45))/0.94=75.048
Z1=245.45+75-100=220.49
2nd Iteration
X2 = (27-0.06(75.048))/0.11=204.519
Y2= (73-0.01(201.519))/0.94=75.48
Z2=204.519+75.48-100=179.99
MATLAB Code:
iter 3
k3
n3
X [204.2815;75.486;179]
Definition:
Simpson’s 1/3rd rule is an extension of trapezoidal rule when the
integrand is approximated by a 2nd order polynomial
Derivation:
Approximating f (x) by a 2nd order polynomial as
( a+b )
(
f 2 ( x)=b0 +b1 ( x − a ) +b2 ( x − a ) x −
2 )
Where b0= f ( a )
( a+b )
b=1
( f
2 )
− f (a )
a+b
−a
2
b 2=¿)/(b-a)
b b
∫ f ( x ) dx =∫ f 2 ( x ) dx
a a
b
a+ b
¿ ∫ b0 + b1 ( x −a ) + b2 ( x −a ) x −
a
( 2
dx )
2
¿ b0 x +b1 ([ x2
2
−ax ) +b3
3] [(
x 3 ( 3 a+ b ) x ( a ( a+b ) x )
−
4
+
2 )] b
a
b2 −a2
¿ b0 ( b − a ) +b1
b
[2
− a( b− a) +b 2 ¿ ]
∫ f ( x ) dx= b −6 a f ( a ) + 4 f a+2 b + f (b)
[ ( ) ]
a
ℎ a+ b
[3
¿ f ( a) + 4 f (
2 )
+ f (b)
]
Description:
It is a process used for integration. It has a mole accuracy
than trapezoidal rule, Since trapezoidal rule was based on approximating
the integrand by a first order polynomial and then integrating the
polynomial over interval of integration.
Question:
A gaseous reactant A decomposes as A3R, -rA=0.6 CA/min
with CA0=300m.mol/lit to a lm3 PFR. where conversion is XA=0.88 find
the volumetric flow rate.
For PFR
XA
V T
= ( d X A )/− r A ¿
F A0 C A0 ∫
=
0 ¿
EA=3*0.5+0.5-1
0.88
1000 lit d X A ( 1+ x )
10 −3 mol
= ∫ 0.6∗ C A 0 ∗(1 − x )
300∗ ∗ γ0 0
lit
0.88
1000 lit 1+ x
0.6 ∗ =∫ dx
γ0 0 1−x
1+ x
Here f ( x )= 1 − x
Taking step size=h=0.2
X 0 0.22 0.44 0.66 0.88
F(X) 1 1.5641 2.57143 4.8823 15.667
0.22
¿ [ 1+ 15.667+4 (1.5641+2.51743+4.8823) ]
3
=3.86748
1000
γ 0=0.6∗
3.86748
γ 0=156 lit /min
MATLAB Code:
clc
clear all;
close all;
f=@(x) 1+x/1-x;
a=0; b=0.88;
n=b-a;
h=(b-a)/n;
p=0;
for i=a:b
p=p+1;
x(p)=i;
y(p)=i+1/i-1;
end
l=length(x);
x
y
answer=(h/3)*((y(1)+y(l))+2*(y(3)+y(5))+4*(y(2)+y(4)+y(6)))
Output:
h 0.22
x 3.47
Secant Method:
Definition:
One of the drawback of newton’s method is it is necessary to
evaluate f’(x) at various points, which may not be practical for some
choices of f. The secant method avoids this issue by using a finite
difference to approximate the derivative.
Derivation:
It can be noted that f(x) is approximated by a secant line through 2
points on the graph of f, rather than a tangent line through one point on
the graph.
Since a secant line is defined using 2 points on the graph of f(x), it
is necessary to choose 2 initial iterates.
From the newton Raphson method of solving a nonlinear equation
f(x)=0, we have
Xi+1 = Xi – (f(Xi)/f’(Xi))
To overcome the drawbacks the derivative of the function f(X) is
taken as
f’(Xi) = (f(Xi) – f(Xi-1))/(Xi – Xi-1)
Xi+1 = Xi – ( (f(Xi)* (Xi – Xi-1))/ f(Xi) – f(Xi-1))
Which is secant method.
Description:
This method uses 2 initial guesses but unlike the bisection method,
the 2 initial guesses do not need to bracketed the root of the equation.
This is an open method which may or may not converge, but if secant
method converges, it will typically converge faster than bisection
method, but it typically converges slower than Newton Raphson method.
Question:
The floating ball has a specific gravity of 0.6 and radius 5.5cm, depth X
to which the ball is submerged under water is given by
X3 - 0.165*X2 + 3.993*10-4 = 0
Find the depth X to which the ball is submerged under water
Given
f(X) = X3 - 0.165*X2 + 3.993*10-4 = 0
let us assume initial guesses of the root as
X-1 = 0.02, X0 = 0.05
Iteration – 1
X1 = X0 – ( (f(X0)* (X0 – X-1))/ f(X0) – f(X-1))
Substituting we get
X1 = 0.06461
|Ea| = |(X1 – X0)/X1|*100%
=22.62%
Iteration – 2
X2 = X1 – ( (f(X1)* (X1 – X0))/ f(X1) – f(X0))
X2 = 0.06241
|Ea| = |(X2 – X1)/X2|*100%
= 3.525%
Iteration – 3
X3 = X2 – ( (f(X2)* (X2 – X1))/ f(X2) – f(X1))
X3 = 0.06238
|Ea| = |(X3 – X2)/X3|*100%
= 0.0595%
Here the root converges at X = 0.06238
MATLAB Code:
f=@(x) ((x^3)-(0.165*(x^2))+(3.993*0.0001));
x(0)=0.02;
x(1)=0.05;
n=0.0005
iteration=0;
for i=2:10
x(i)=x(i-1)-(f(x(i-1)))*((x(i-1)-x(i-2))/(f(x(i-1))-f(x(i-2))));
iteration=iteration+1;
if abs((x(i)-x(i-1))/x(i))*100<n
root=x(i);
iteration=iteration;
break
end
end
Output:
i3
x 0.06238
Bisection Method:
Definition:
Derivation:
The steps to apply the bisection method to find the root of the equation
f (x )=0 are
1. Choose x ℓ and x u as two guesses for the root such that
f (x ℓ )f ( x u )<0 , or in other words, f (x ) changes sign between x ℓ
and x u .
Description:
At least one root exists between the two points if the function is
real, continuous, and changes sign
f (x)
xℓ
x
xu
If the function f (x ) does not change sign between the two points,
roots of the equation f (x )=0 may still exist between the two
points
f (x)
x
xℓ xu
If the function f (x ) does not change sign between two points,
there may not be any roots for the equation f (x )=0 between the
two points
f (x) f (x)
xℓ xu
x x
xℓ xu
xu
x
xℓ
Question:
You have a spherical storage tank containing oil. The tank has a
diameter of 6 ft. You are asked to calculate the height h to which a
dipstick 8 ft long would be wet with oil when immersed in the tank
3
when it contains 4 ft of oil. The equation that gives the height, h , of
the liquid in the spherical tank for the given volume and radius is given
by :
3 2
f ( h )=h −9 h +3 .8197=0
Solution
From the physics of the problem, the dipstick would be wet between
h=0 and h=2r , where
r= radius of the tank,
that is
0≤h≤2 r
0≤h≤2(3)
0≤h≤6
Let us assume
hℓ =0 , hu =6
Check if the function changes sign between hℓ and hu .
3 2
f (hℓ )=f ( 0 )=( 0 ) −9 ( 0 ) +3. 8197=3 . 8197
3 2
f (hu )=f (6)=(6 ) −9(6 ) +3 . 8197=−104 .18
Hence
f ( hℓ ) f ( hu ) =f ( 0 ) f ( 6 )=( 3 . 8197 ) (−104 .18 )< 0
Iteration 1
The estimate of the root is
h ℓ +hu
hm =
2
0+6
=
2
=3
f ( hm )=f ( 3 )=( 3 )3 −9 ( 3 )2 +3 .1897=−50 .180
f ( hℓ ) f ( hm )=f ( 0 ) f ( 3 )= ( 3. 1897 ) (−50 .180 ) < 0
Hence the root is bracketed between hℓ and hm , that is, between 0 and
3. So, the lower and upper limits of the new bracket are
hℓ =0 , hu =3
At this point, the absolute relative approximate error |∈a| cannot be
calculated, as we do not have a previous approximation.
Iteration 2
The estimate of the root is
h ℓ +hu
hm =
2
0+3
=
2
=1.5
f ( hm )=f ( 1. 5 )=( 1 .5 )3−9 (1 . 5 )2 +3 . 8197=−13. 055
f ( hℓ ) f ( hm )=f ( 0 ) f ( 1 .5 ) =( 3. 8197 )(−13 . 055 ) <0
Iteration 3
The estimate of the root is
h ℓ +hu
hm =
2
0+1 .5
=
2
=0. 75
f ( hm )=f ( 0 .75 ) =( 0 .75 )3 −9 ( 0 . 75 )2 +3 . 8197=−0 .82093
f ( hℓ ) f ( hm )=f ( 0 ) f ( 0 . 75 )=( 3 . 8197 ) (−0 .82093 )< 0
Hence, the root is bracketed between hℓ and hm , that is, between 0 and
0.75. So the lower and upper limits of the new bracket are
hℓ =0 , hu =0 . 75
The absolute relative approximate error |∈a| at the end of Iteration 3 is
new old
hm −h m
|∈a|=| |×100
hnew
m
0.75−1.5
=| |×100
0.75
=100 %
Still none of the significant digits are at least correct in the estimated
root of the equation as the absolute relative approximate error is greater
than 5% .
The height of the liquid is estimated as 0.75 ft at the end of the third
iteration.
Seven more iterations were conducted and these iterations are shown in
the table:
Iteratio hℓ hu hm |∈a|% f ( hm )
n
3
0.00
1.5
0.00 ---------
0.75
1 0.00 6 - −50.180
0.375
2 0.00 3 100 −13.055
0.5625
3 0.375 1.5 100 −0.82093
0.6562
4 0.5625 0.75 100 2.6068
5
5 0.6562 0.75 33.333 1.1500
0.7031
6 5 0.75 14.286 0.22635
3
7 0.6562 0.75 6.6667 −0.28215
0.6796
8 5 0.70313 3.4483 −0.024077
9
9 0.6562 0.67969 1.7544 0.10210
0.6679
10 5 0.67969 0.8695 0.039249
7
0.6679 7
0.6738
7
3
th
At the end of the 10 iteration,
|∈a|=0.86957%
The estimated root is 0.67383.
MATLAB Code:
clc;
clear all;
close all;
a=0;
b=6;
bif=@(x) (x^3-(9*(x^2))+3.8197);
for i=1:100
c=(a+b)/2;
if bif(a)*bif(c)<0
b=c;
else
a=c;
end
end
Output:
i 100
c 0.6775
Definition:
Derivation:
There are 3 kinds of elementary row operations which are discussed
below:
i) Switching of Rows:
A row can be interchanged with another row.
Ri↔Rj
Question:
The waste acid from a nitrating process contains 21% HNO 3, 55% H2SO4
and 24% H2O by weight. This acid is concentrated to contain 28%
HNO3, 62% H2SO4 by the addition of concentrated sulphuric acid
containing 93% H2SO4 and concentrated nitric acid containing 90%
HNO3. Calculate the weights of waste and concentrated acids that must
be combined to obtain 1000 lb of the desired mixture.
Solution:
93% H2SO4 , 90% HNO3
Therefore,
X = 126.789;
Y = 591.68;
Z= 291.52
MATLAB Code:
Output:
X= [126.789 591.68 281.527]
Definition:
Derivation:
Description:
Explicit Method:
Definition:
This explicit method calculate the state of a system at a later time from
the state of the system at the current time.
Derivation:
yk+1 = yk – deltat*yk^2
Description:
Question:
x0=0,y0=1120, h=207.975
solving we get
y1= 792.46
y2=599
MATLAB Code:
clc
clear all
close all
% y' =-2x-y
% initial condition
x(1) = 0;
y(1) = -2;
h = 0.1;% step size
%Euler Forward
%%%%%%%%%%%%%%
for i = 1:10
y(i+1) = y(i)+h*(-2*x(i)-y(i));
x(i+1) = x(i)+h;
end
xlabel('x')
ylabel('y')
%Euler Backward
%%%%%%%%%%%%%%
% yn+1 = (yn -2hxn+1)/(1+h)
for i = 1:10
x(i+1) = x(i)+h;
y(i+1) = (y(i)-2*h*x(i+1))/(1+h);
end
xlabel('x')
ylabel('y')
Output:
%Euler forward
X 415.95
Y 599
%Euler backward
X 415.95
Y 135.23