You are on page 1of 6

Barani Institute of Management Sciences

Final Exam (Practical)/ Fall 2020 (Paper Duration 24 hours)


To be filled by Teacher

Course No.: CS - 572 CourseTitle: Numerical Analysis


Total Marks: 20 Date of Exam: 08-02-2021 (Monday)
Degree: BS(CS) Semester: 5 Section: C
Marks
Q.No. 1 2 3 4 5 6 7 8 9 10 Obtained/
TotalMarks
Marks / 20
Obtained
Total Marks in Words: Twenty
Name of the teacher: Dr. Zaffar Mehmood
Who taught the course: Signature of teacher / Examiner:

To be filled by Student

Registration No.: ……18-Arid-5157…….……… Name:………………………Ibtasam Mateen Javed…………..

Answer the following questions.

Instruction:
Show complete work.
Stepwise solution must be provided.
Answer the following questions. Each question carries equal marks.

Q.No.1. (Marks 10)


A car traveling along a straight road is clocked at a number of points. The data from the observations
are given in the following table, where the time is in seconds, the distance is in feet, and the speed is
in feet per second.
Time 0 3 5 8 13
Distance 0 225 383 623 993
Speed 75 77 80 74 72
1. Use a Divided difference scheme to predict the position of the car and its speed when t =
10s.
2. Use the derivative of the polynomial to determine whether the car ever exceeds a 55 mi/h
speed limit on the road. If so, what is the first time the car exceeds this speed?
3. What is the predicted maximum speed for the car?

Answer:
(2)
we see that the speed of the car does exceed 55 mi/h (80.67 ft/s) somewhere between t = 5
and t = 6. Using the bisection method (see
previous homework for code), we find that the car first exceeds 55 mi/h
at t = 5.64492.

(3)
From the sketch of the velocity, we see that the maximum speed of the car occurs somewhere
between t = 12 and t = 13. Using the bisection method on the second derivative H 00 9 (t) =
−0.0014561t 7 + 0.0582731t 6 − 0.918778t 5 + 7.29124t 4 − 30.7659t 3 + 66.0974t 2 − 60.5719t +
14.3238,
we find that the car reaches is maximum speed of 119.417 ft/s (81.4207 mph) at t = 12.3737 s.

b. Write down the Matlab / C++ code for Jacobi method to solve the following linear systems with
TOL = 10−10.

𝐱 𝟏 + 𝐱 𝟐 + 𝐱 𝟒 = 𝟐,

𝟐𝐱 𝟏 + 𝐱 𝟐 − 𝐱 𝟑 + 𝐱 𝟒 = 𝟏,

−𝐱 𝟏 + 𝟐𝐱 𝟐 + 𝟑𝐱 𝟑 – 𝐱 𝟒 = 𝟒,

𝟑𝐱 𝟏 – 𝐱 𝟐 – 𝐱 𝟑 + 𝟐𝐱 𝟒 = −𝟑,
Answer:

#include<iostream>
#include<iomanip>
#include<math.h>

/* Arrange systems of linear


equations to be solved in
diagonally dominant form
and form equation for each
unknown and define here
*/
/* In this example we are solving
3x + 20y - z = -18
2x - 3y + 20z = 25
20x + y - 2z = 17
*/
/* Arranging given system of linear
equations in diagonally dominant
form:
20x + y - 2z = 17
3x + 20y -z = -18
2x - 3y + 20z = 25
*/
/* Equations:
x = (17-y+2z)/20
y = (-18-3x+z)/20
z = (25-2x+3y)/20
*/
/* Defining function */
#define f1(x,y,z) (17-y+2*z)/20
#define f2(x,y,z) (-18-3*x+z)/20
#define f3(x,y,z) (25-2*x+3*y)/20

using namespace std;

/* Main function */
int main()
{
float x0=0, y0=0, z0=0, x1, y1, z1, e1, e2, e3, e;
int step=1;
/* Setting precision and writing floating point values in fixed-point notation. */
cout<< setprecision(6)<< fixed;

/* Input */
/* Reading tolerable error */
cout<<"Enter tolerable error: ";
cin>>e;

cout<< endl<<"Count\tx\t\ty\t\tz"<< endl;


do
{
/* Calculation */
x1 = f1(x0,y0,z0);
y1 = f2(x0,y0,z0);
z1 = f3(x0,y0,z0);
cout<< step<<"\t"<< x1<<"\t"<< y1<<"\t"<< z1<< endl;

/* Error */
e1 = fabs(x0-x1);
e2 = fabs(y0-y1);
e3 = fabs(z0-z1);

step++;

/* Set value for next iteration */


x0 = x1;
y0 = y1;
z0 = z1;
}while(e1>e && e2>e && e3>e);

cout<< endl<<"Solution: x = "<< x1<<", y = "<< y1<<" and z = "<< z1;


return 0;
}

Q.No.2. (Marks 10)


a. Write the Matlab / C++ routine of Runge-Kutta method of Order four for the following problem
(𝐲 𝟐 + 𝐱 𝟐 )𝐲 ′ − 𝐲 𝟐 + 𝐱 𝟐 = 𝟎, 𝐲(𝟎) = 𝟏

where 0 ≤ x ≤ 0.4, by taking h = 0.2

Answer:
%RUNGE KUTTA METHOD OF ORDER FOUR
clc;clear; % Clears the screen
h=0.025; % step size
x = 0.1:h:0.5;
y = zeros(1,length(x));
y(1) = 4; % initial condition,y(1) is
y(0) value
F_xy = @(x,y) 3*x^2+y; % function
for i=1:(length(x)-1) % calculation loop
k_1 = F_xy(x(i),y(i));
k_2 = F_xy(x(i)+0.5*h,y(i)+0.5*h*k_1);
k_3 = F_xy((x(i)+0.5*h),(y(i)+0.5*h*k_2));
k_4 = F_xy((x(i)+h),(y(i)+k_3*h));
y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h; % main equation
end
for i=1:(length(x))
fprintf('%12.5f',x(i),y(i));fprintf('\n')
end

b. Explain your project in detail.

Answer:
: In my project I was given 2 topics Bisection and Euler
In project first we have to describe our topic with detail and look onto the formula and tell what
values we have to put in the formula after that I will take an example start explaining full example
after that I will write a c++ program for a specific example and I will tell what is happening in the
program. And after that I will take second topic and vice virsa.

Good Luck!!☺

You might also like