Professional Documents
Culture Documents
1
Name: A U Nachiketh Kumar Course: M4-Matlab
Declaration Sheet
Student Name A U Nachiketh Kumar
Reg. No 20ETAS012001
Programme B. Tech Semester/Year 4/2
Course Code 20MTB211A
Course Title Engineering Mathematics – 4
Course Date To
Dr Gireesh D. S. / Dr Shivashankar C. / Dr Somashekhara G. /
Course Leader
Dr. Sumanth Bharadwaj H. S.
Declaration
The assignment submitted herewith is a result of my own investigations and that I have
conformed to the guidelines against plagiarism as laid out in the Student Handbook. All
sections of the text and results, which have been obtained from other sources, are fully
referenced. I understand that cheating and plagiarism constitute a breach of University
regulations and will be dealt with accordingly.
Signature of the
Date
Student
Submission date
stamp
(by Examination & Assessment
Section)
Signature of the Course Leader and date Signature of the Reviewer and date
Name: A U Nachiketh Kumar Course: M4-Matlab
Part – A
1.1 Consider the IVP:
dy
= −y + x√y , y(2) = 2,2 ≤ x ≤ 3.
dx
1.1.2 Determine the solution at 𝑥=3 using modified Euler’s method for step size
ℎ= 0.05,0.1,0.2,0.24,0.5,1.0 with the help of a MATLAB program. Tabulate the
solution at 𝑥=3 and plot a graph of relative error vs ℎ and comment.
Name: A U Nachiketh Kumar Course: M4-Matlab
PROGRAM CODE:
%Eulers Method
function [] = EulersMethod(x0,y0,h,xn)
f = @(x,y) -y + x*sqrt(y);
n = round((xn-x0)/h);
x = x0:h:xn;
y(1) = y0;
for i=1:n
y(i+1) = y(i) + h*f(x(i),y(i));
fprintf('The value of y when x is %f will be
%f\n',x(i+1),y(i+1))
end
% Input: x0 = 2; y0 = 2; xn = 3; h = 0.25;
EulersMethod(x0,y0,h,xn)
OUTPUT:
>> EulersMethod(x0,y0,h,xn)
The value of y when x is 2.250000 will be 2.207107
The value of y when x is 2.500000 will be 2.490999
The value of y when x is 2.750000 will be 2.854680
The value of y when x is 3.000000 will be 3.302596
Engineering Mathematics - 1 4
Name: A U Nachiketh Kumar Course: M4-Matlab
PLOT:
Engineering Mathematics - 1 5
Name: A U Nachiketh Kumar Course: M4-Matlab
PROGRAM CODE:
%Input: x0 = 2; y0 = 2; xn = 3; h = 0.25;
ModifiedEulersMethod(x0,y0,h,xn)
OUTPUT:
>> ModifiedEulersMethod(x0,y0,h,xn)
The value of y when x is 2.250000 will be 2.245499
The value of y when x is 2.500000 will be 2.567156
The value of y when x is 2.750000 will be 2.969195
The value of y when x is 3.000000 will be 3.456568
Engineering Mathematics - 1 6
Name: A U Nachiketh Kumar Course: M4-Matlab
PLOT:
Engineering Mathematics - 1 7
Name: A U Nachiketh Kumar Course: M4-Matlab
PROGRAM CODE:
%Input: x0 = 2; y0 = 2; xn = 3; h = 0.25;
RangeKutta4(x0,y0,h,xn)
OUTPUT:
>> RangeKutta4(x0,y0,h,xn)
Value of y when x is 2.250000 will be 2.244119
Value of y when x is 2.500000 will be 2.564449
Value of y when x is 2.750000 will be 2.965189
Value of y when x is 3.000000 will be 3.451281
Engineering Mathematics - 1 8
Name: A U Nachiketh Kumar Course: M4-Matlab
PLOT:
Engineering Mathematics - 1 9
Name: A U Nachiketh Kumar Course: M4-Matlab
1.1.2 Determine the solution at 𝑥=3 using modified Euler’s method for step size
ℎ= 0.05,0.1,0.2,0.24,0.5,1.0 with the help of a MATLAB program. Tabulate the
solution at 𝑥=3 and plot a graph of relative error vs ℎ and comment.
%INPUT
%{
Input: x0 = 2; y0 = 2; xn = 3; h = [0.05 0.1 0.2 0.25 0.5
1];
Engineering Mathematics - 1 10
Name: A U Nachiketh Kumar Course: M4-Matlab
OUTPUT:
Solution at x = 3 by Modified Eulers Method when step size h = 0.050000 is 3.451502
Solution at x = 3 by Modified Eulers Method when step size h = 0.100000 is 3.452146
Solution at x = 3 by Modified Eulers Method when step size h = 0.200000 is 3.454688
Solution at x = 3 by Modified Eulers Method when step size h = 0.250000 is 3.456568
Solution at x = 3 by Modified Eulers Method when step size h = 0.500000 is 3.471601
Solution at x = 3 by Modified Eulers Method when step size h = 1.000000 is 3.522689
PLOT
Engineering Mathematics - 1 11