0% found this document useful (0 votes)
5 views5 pages

Scilab 1.1

The document provides a series of SCILAB code examples demonstrating various numerical methods for solving ordinary differential equations, including Picard's method, Taylor series, Euler's method, and the Runge-Kutta method. Each section includes specific problems with initial conditions and iterative calculations to approximate solutions at given points. The results of the computations for each method are displayed, showcasing the approximate values of the solutions after the specified iterations.

Uploaded by

Ravan Samrajya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Scilab 1.1

The document provides a series of SCILAB code examples demonstrating various numerical methods for solving ordinary differential equations, including Picard's method, Taylor series, Euler's method, and the Runge-Kutta method. Each section includes specific problems with initial conditions and iterative calculations to approximate solutions at given points. The results of the computations for each method are displayed, showcasing the approximate values of the solutions after the specified iterations.

Uploaded by

Ravan Samrajya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Console

Startup execution: loading


initial environment

--> // Tutorial 8

--> //Name : Bhumi Bhadre

--> //Roll no : 106 Div : A

--> // Q.Write a SCILAB code for the following question

--> //Q1.Use Picard's method to solve dy/dx=x+y,y(0)=1,compute y(0.1) after 3 iterations.

--> //Given intial condition

--> y = 1;

--> //1st iteration is given by

--> y = 1 + integrate('s + 1','s',0,0.1);

--> disp("1st approx value is : y(0.1) = " + string(y));

"1st approx value is : y(0.1) = 1.105"

--> //2nd iteration is given by

--> y = 1 + integrate('s + (1 + s + s^2 / 2)','s',0,0.1);

--> disp("2nd approx value is : y(0.1) = " + string(y));

"2nd approx value is : y(0.1) = 1.1101667"

--> //3rd iteration is given by

--> y = 1 + integrate('s + (1 + s + s^2 / 2 + s^3 / 6)','s',0,0.1);

--> disp("3rd approx value is : y(0.1) = " + string(y));

"3rd approx value is : y(0.1) = 1.1101708"

-->

-->

--> //Q2.Apply Picard’s method to solve,dy/dx=x^2+y^2,y(0)=0,Compute y(0.1) using 4 iterations.

--> //Given intial condition

--> y = 0;

--> //1st iteration is given by

--> y = 1 + integrate('s^2 + 0^2','s',0,0.1);

--> disp("1st approx value is : y(0.1) = " + string(y));

"1st approx value is : y(0.1) = 1.0003333"

--> //2nd iteration is given by


--> y = 1 + integrate('s^2 + (s^3 / 3)^2','s',0,0.1);

--> disp("2rd approx value is : y(0.1) = " + string(y));


"2rd approx value is : y(0.1) = 1.0003333"

--> //3rd iteration is given by

--> y = 1 + integrate('s^2 + (s^3 / 3 + s^7 / 63)^2','s',0,0.1);

--> disp("3rd approx value is : y(0.1) = " + string(y));

"3rd approx value is : y(0.1) = 1.0003333"

--> //4th iteration is given by

--> y = 1 + integrate('s^2 + (s^3 / 3 + s^7 / 63 + 2*s^11 / 2079 + s^15 / 59535)^2','s',0,0.1);

--> disp("4th approx value is : y(0.1) = " + string(y));

"4th approx value is : y(0.1) = 1.0003333"

-->

-->

--> //Q3.Using Taylor series, compute approximate value of y(0.1) for, dy/dx= x^2 + y, y(0)=1, Up to terms containing third order.

--> //By Taylor Series Method for dy/dx = x^2 + y , y(0) = 1

--> //Initial values

--> x0 = 0;

--> y0 = 1;

--> x = 0.1;

--> //First derivative : y' = x^2 + y

--> y1 = 0^2 + y0;

--> //Second derivative : y'' = dy/dx(x^2 + y) = 2x + y'

--> y2 = 2*0 + y1;

--> //Third derivative : y''' = dy/dx(2x + y') = 2 + y''

--> y3 = 2 + y2;

--> //Taylor Series : y(x)≈ y0 + y1*x + y2*x^2/2 + y3*x^3/ 6

--> y_approx = y0 + y1*x + (y2*x^2)/2 + (y3*x^3)/6;

--> disp("The approximate value of y(0.1) upto 3rd order :");disp(y_approx )

"The approximate value of y(0.1) upto 3rd order :"

1.1055

-->

-->

--> //Q4.Apply Taylor series method up to 3rd order to solve dy/dx= x+y ,y(0)=2 Compute y(0.1).
--> //By Taylor Series Method for dy/dx = x + y , y(0) = 2

--> //Initial values

--> x0 = 0;
--> y0 = 2;

--> x = 0.1;

--> //First derivative : y' = x + y

--> y1 = 0 + y0;

--> //second derivative : y'' = 1 + y1;

--> y2 = 1 + y1;

--> //Third derivative : y''' = d/dx(1 + y') = y''

--> y3 = y2;

--> //Taylor series: y(x) ≈ y0 + y1*x + y2*x^2/2 + y3*x^3/ 6

--> y_approx = y0 + y1*x + (y2*x^2)/2 + (y3*x^3)/6;

--> disp("The approximate value of y(0.1) upto 3rd order is :") ; disp(y_approx )

"The approximate value of y(0.1) upto 3rd order is :"

2.2155000

-->

-->

--> //Q5.Use Euler’s method with step size ℎ=0.1 to approximate solution of,dy/dx=x+y, y(0)=1,From x=0 to x=0.5.

--> //Euler's method to solve dy/dx = x + y with y(0) = 1

--> // Define function f(x, y) = x + y

--> function z = f(x, y )


> z = x + y;
> endfunction

--> x0 = 0;

--> y0 = 1;

--> h = 0.1;

--> n = 5;

--> disp(" x y (Euler Approx)");

"x y (Euler Approx)"

--> for i = 0:n


> disp(string(x0) + " " + string(y0));
> y0 = y0 + h * f(x0, y0);
> x0 = x0 + h;

> end

"0 1"
"0.1 1.1"

"0.2 1.22"

"0.3 1.362"

"0.4 1.5282"

"0.5 1.72102"

-->

-->

--> //Q6.Solve the following using Euler’s method with h=0.2 dy/dx = y−x,y(0)=2 Compute y(0.2) and y(0.4).

--> //Euler's Method to sovle dy/dx = y-x with y(0) = 2

--> //Define function g(x, y) = y - x

--> function m = g(x, y )


> m = y - x;
> endfunction

--> x = 0;

--> y = 2;

--> h = 0.2;

--> x_end = 0.4;

--> disp(" x y (Euler Approx)");

"x y (Euler Approx)"

--> // Euler's method using while loop

--> while x <= x_end


> disp(string(x) + " " + string(y));
> y = y + h * f(x, y);
> x = x + h; >
end

"0 2"

"0.2 2.4"

"0.4 2.92"

-->

-->

--> //Q7.Apply Runge-Kutta method to solve dy/dx=x+y, y(0)=1 Compute y(0.1) using step size ℎ = 0.1.

--> // Define the function f(x, y) = x + y

--> function z = f(x, y )


> z = x + y;
> endfunction

-->

--> // Initial conditions


--> x = 0;

--> y = 1;

--> h = 0.1;

-->

--> // Runge-Kutta 4th order calculations


--> k1 = h * f(x, y);

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

--> k3 = h * f(x + h/2, y + k2/2);

--> k4 = h * f(x + h, y + k3);

--> y_next = y + (1/6)*(k1 + 2*k2 + 2*k3 + k4);

--> x_next = x + h;

--> disp("Approximate value of y(0.1) using RK4 method is:");disp(y_next);

"Approximate value of y(0.1) using RK4 method is:"

1.1103417

You might also like