You are on page 1of 3

Name :

Roll number :
Division : INFT - D5B
Academic Year : 2022-23
Batch : 61 onwards (Q7)
---------------------------------------------------------------------------------------------------------

MATHS SCILAB Practical No. 1


Modified Euler’s Method
Using suitable loop, write a scilab program to obtain approximate
solution of y, using Modified Euler’s Method (upto 5 decimal
places).
Q7 - dy/dx = x + y^2; y(0)=1, x=0.2, h=0.1

INPUT –
function dydx=f(x, y)
dydx = x + y^2;
endfunction

// User input
x0 = 0.2;
y0 = 1;
h = 0.1;
xn = input("Enter the final value of xn: ");
n = (xn - x0) / h;

// Modified Euler's Method


x = x0;
y = y0;

mprintf("step=\n");
mprintf("at x=\n");
mprintf("Euler solution y=\n");
mprintf("modified solution =\n");

for i = 1:n
mprintf("Step = %.1f\n", h);
mprintf("At x = %.1f\n", x);
mprintf("Euler solution y = %.5f\n", y);
mprintf("Modified solution = %.5f\n", y);

k1 = f(x, y);
k2 = f(x + h, y + h * k1);
y = y + (h / 2) * (k1 + k2);
x = x + h;
end

mprintf("Step = %.1f\n", h);


mprintf("At x = %.1f\n", x);
mprintf("Euler solution y = %.5f\n", y);
mprintf("Modified solution = %.5f\n", y);
OUTPUT -
Enter the final value of xn: 0.5
step=
at x=
Euler solution y=
modified solution =
Step = 0.1
At x = 0.2
Euler solution y = 1.00000
Modified solution = 1.00000
Step = 0.1
At x = 0.3
Euler solution y = 1.13772
Modified solution = 1.13772
Step = 0.1
At x = 0.4
Euler solution y = 1.32157
Modified solution = 1.32157
Step = 0.1
At x = 0.5
Euler solution y = 1.57190
Modified solution = 1.57190

You might also like