Assignment #1
Assignment #1
Question 1:
5. (x - √(x)) / (5x2 – 3)
SOLUTION
7. (x3 + 4)4
SOLUTION
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
2. cos x + x
SOLUTION
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
3. 8z + 4z3 − 6z2
SOLUTION
4. x √(x+1)
SOLUTION
5. √(x^3+1)
SOLUTION
6. x / x2 +1
SOLUTION
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
7.
SOLUTION
x 2 x −1
2. lim
n→ 0 x
SOLUTION
e 5 x −1
3. lim
n→ 0 x
SOLUTION
1
4. lim (1−5) x
n→ 0
SOLUTION
8x
log(1+ )
5. 3
lim
n→ 0 x
SOLUTION
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
Question 2:
(a) Implement the following using Bisection Method.
double x = 0;
double E = 0.0001;
}
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
if (f_x1 < 0){
a = x1; b=
x2;
} else
{ a=
x2; b=
x1;
}
do{
"+i+"\n*************************");
xn = (a + b)/2;
[Link]("xn = "+xn);
f_xn = [Link](xn,3) - 5*xn + 3;
[Link]("f_xn = "+f_xn);
[Link]("b = "+b);
} else{
a = xn;
[Link]("a = "+a);
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
} abs_val = (b - a)/b; abs_val =
[Link](abs_val);
[Link]("abs_val = "+abs_val);
i++;
}
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
Output
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
import [Link];
public class Main
double x = 0;
double E = 0.0001;
} else
{ a=
x2; b=
x1;
}
do{
"+i+"\n*************************");
xn = (a + b)/2;
[Link]("xn = "+xn);
f_xn = [Link](xn,2) - 2*xn - 2;
[Link]("f_xn = "+f_xn);
[Link]("b = "+b);
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
}
else{ a
= xn;
[Link]("a = "+a);
abs_val = (b - a)/b;
abs_val = [Link](abs_val);
[Link]("abs_val = "+abs_val); i+
+;
root = (a+b)/2;
}
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
OUTPUT
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
public static
void main(String[] args)
{ double x = 1;
int N; int i
= 1; double error;
N = [Link]();
int step = 1;
do {
[Link]("\n\tIteration number:
"+i); double f_x0 = 2*[Link](x0,3) - 3*x0 - 6;
double g_x0 = 6*[Link](x0,2) - 3; if
(g_x0 == 0){
[Link]("\tMathematical Error!");
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
[Link](0);
} x1 = x0 - (f_x0/g_x0);
x0 = x1;
[Link]("\tNot Convergent");
OUTPUT
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
2. Let f(x) = 3x2 – 72x – 220. Given that f(x) = 0 has a root near x = 12, compute x 1 ,starting
with x0 = 26.
SOURCE CODDING
import [Link];
class Main
= 1;
error = [Link]();
N = [Link]();
int step = 1;
do {
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
[Link]("\n\tIteration number: "+i);
[Link]("\tMathematical Error!");
[Link](0);
} x1 = x0 - (f_x0/g_x0);
x0 = x1;
[Link]("\tNot Convergent");
} f_x1 = 3*[Link](x1,2) -
i++;
OUTPUT
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
Question 3:
step = step + 1
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
condition = abs(f(x2)) > e
step = step + 1
condition = abs(f(x2)) > e
# Input Section
x0 = input('First Guess: ')
x1 = input('Second Guess: ')
e = input('Tolerable Error: ')
1. A trunnion has to be cooled before it is shrink fitted into a steel hub. The equation that gives
the temperature x to which the trunnion has to be cooled to obtain the desired contraction is
given by the following equation.
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
f(x)= x2 – 2x – 15 =0
SOURCE CODDING
if f(a)*f(b) >= 0:
print("Secant method fails.")
return None
a_n = a
b_n = b
for n in range(1,N+1):
m_n = a_n - f(a_n)*(b_n - a_n)/(f(b_n) - f(a_n))
f_m_n = f(m_n)
if f(a_n)*f_m_n < 0:
a_n = a_n
b_n = m_n
elif f(b_n)*f_m_n < 0:
a_n = m_n
b_n = b_n
elif f_m_n == 0:
print("Found exact solution.")
return m_n
else:
print("Secant method fails.")
return None
return a_n - f(a_n)*(b_n - a_n)/(f(b_n) - f(a_n))
p = lambda x: x**2 - 2*x - 15
print(p(1))
print(p(2))
print(p(3))
OUTPUT
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
2. Finding roots of equation. To find the temperature x to which the trunnion has to be cooled.
conduct three iterations to estimate the root of the above equation.
SOLUTION
Iteration 1
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
Iteration 2
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
Iteration 2
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
Question 4:
5 1 2 x 1 1
1. Let A= 1
[ ] [] []
2 2 5 z 3
to approximate solution to the system Ax=b.
[]
4 2 , x= y and let b= 2 . with the initial approximation x0 = 1 with n iterations
1
CODDING
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
2. Determine whether the Jacobi Iteration method will converge to the solution.
SOURCE CODDING
import numpy as np
B=[]
n = int(input("Enter the number of rows in a matrix: "))
a = [[0] * n for i in range(n)]
t=len(a)
x=[1]*len(a)
c=[0]*len(a)
for i in range(n):
for j in range(n):
a[i][j] = int(input("Enter Coefficient:"))
print("Matrix of A:\n",[Link](a))
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
for i in range(t):
b=int(input("Enter Coefficient For b:"))
[Link](b)
print("Matrix of B:\n",[Link](B))
print("Matrix of X:\n",[Link](x))
print("\n**** GAUSS JACOBI METHOD ****\n")
for i in range(0,n):
c[i]=B[i]
for j in range(0,n):
if(i != j):
c[i] =c[i]- a[i][j] * x[j]
x[i] = c[i] / a[i][i]
print(x)
Question 5:
(a) Implement the following using fixed point iteration.
1 1 −x
1. Let’s take g(x) = e –x as our example. Will the iteration x n+1= e ?
n
2 2
SOURCE CODE:
#include <stdio.h>
#include <math.h>
double f(double x)
{
return x*x*x*x-3*x*x-3; //change equation for each problem
}
double g(double x)
{
return pow(3*x*x+3,.25);
}
int main()
{
double p, p0, Tol;
int i=1;
int No;
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
while (i<=No)
{
p = g(p0);
if((fabs(p-p0))<Tol)
{
//printf("%lf", &p);
break;
}
printf("Iteration %d: Current value = %lf\n", i, p);
i++; //i=i+1
p0=p;
if (i>No)
{
printf("Method Failed after %d", No);
printf(" iterations");
}
}
}
OUTPUT
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
1
2. Let g(u) = 1+ u - u 3. Find all fixed point of g(u).
8
SOURCE CODDING
#include <stdio.h>
#include <math.h>
double f(double x)
{
return x*x*x*x-3*x*x-3; //change equation for each problem
}
double g(double x)
{
return pow(3*x*x+3,.25);
}
int main()
{
double p, p0, Tol;
int i=1;
int No;
while (i<=No)
{
p = g(p0);
if((fabs(p-p0))<Tol)
{
//printf("%lf", &p);
break;
}
printf("Iteration %d: Current value = %lf\n", i, p);
i++; //i=i+1
p0=p;
if (i>No)
{
printf("Method Failed after %d", No);
printf(" iterations");
}
}
OUTPUT
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
3. Find a root of the function (𝑥) = cos(𝑥) − 𝑥 when the initial guess x0 = 0 and 𝑔(𝑥) = cos(𝑥).
SOURCE CODDING
#include <stdio.h>
#include <math.h>
double f(double x)
{
return x*x*x*x-3*x*x-3; //change equation for each problem
}
double g(double x)
{
return pow(3*x*x+3,.25);
}
int main()
{
double p, p0, Tol;
int i=0;
int No;
while (i<=No)
{
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
p = g(p0);
if((fabs(p-p0))<Tol)
{
//printf("%lf", &p);
break;
}
printf("Iteration %d: Current value = %lf\n", i, p);
i++; //i=i+1
p0=p;
if (i>No)
{
printf("Method Failed after %d", No);
printf(" iterations");
}
}
Output
4. Let f(x) = x^3 + x^2 -1, find all fixed point of g(x).
SOURCE CODDING
#include <stdio.h>
#include <math.h>
double f(double x)
{
return x*x*x*x-3*x*x-3; //change equation for each problem
}
double g(double x)
{
return pow(3*x*x+3,.25);
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
}
int main()
{
double p, p0, Tol;
int i=0;
int No;
while (i<=No)
{
p = g(p0);
if((fabs(p-p0))<Tol)
{
//printf("%lf", &p);
break;
}
printf("Iteration %d: Current value = %lf\n", i, p);
i++; //i=i+1
p0=p;
if (i>No)
{
printf("Method Failed after %d", No);
printf(" iterations");
}
OUTPUT
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
Question 6:
(a) Implement the following using Newton’s interpolation formula.
0.10 0.1003
0.15 0.1511
0.20 0.2027
0.25 0.2553
0.30 0.3093
CODDING
#include<stdio.h>
main()
{
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
int n,i,j,k;
scanf("%d",&n);
for (i=0;i<=n;i++)
scanf("%f %f",&ax[i],&ay[i]);
scanf("%f",&x);
h=ax[1]-ax[0];
for (i=0;i<=n-1;i++)
diff[i][1] = ay[i+1]-ay[i];
for (j=2;j<=ORDER;j++)
for(i=0;i<=n-j;i++)
//now finding x0
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
i=0;
while (!(ax[i]>x))
i++;
//now ax[i] is x0 and ay[i] is y0
i--;
p = (x-ax[i])/h;
yp = ay[i];
for (k=1;k<=ORDER;k++)
nr *=p-k+1;
dr *=k;
yp +=(nr/dr)*diff[i][k];
}
SOLUTION
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
-0.75 -0.0718125
-0.5 -0.02475
-0.25 0.3349375
0 1.101
SOURCE CODDING
#include<stdio.h>
#define ORDER 4
main()
{
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
int n,i,j,k;
scanf("%d",&n);
for (i=0;i<=n;i++)
scanf("%f %f",&ax[i],&ay[i]);
printf("\nEnter the value of x for which the value of f(x) is wanted: \n");
scanf("%f",&x);
h=ax[1]-ax[0];
for (i=0;i<=n-1;i++)
diff[i][1] = ay[i+1]-ay[i];
for (j=2;j<=ORDER;j++)
for(i=0;i<=n-j;i++)
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
diff[i][j] = diff[i+1][j-1] - diff[i][j-1];
//now finding x0
i=0;
while (!(ax[i]>x))
i++;
i--;
p = (x-ax[i])/h;
yp = ay[i];
for (k=1;k<=ORDER;k++)
nr *=p-k+1;
dr *=k;
yp +=(nr/dr)*diff[i][k];
}
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
3. Estimate the population for the year 1925 using given below year and population details.
Year(x) Population (y)
1891 46,000
1901 66,000
1911 81,000
1921 93,000
1931 1,01,000
SOURCE CODDING
int main()
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
{
// number of values given
int n = 5;
float x[] = { 1891, 1901, 1911,
1921, 1931 };
// Value to interpolate at
float value = 1925;
cout << "\n Value at " << value << " is "
<< sum << endl;
return 0;
}
OUTPUT
Question 7:
Implement the following using Newton’s divided difference polynomial method.
1. Find the polynomial of the lowest possible degree which assumes the values -21, 15, 12, 3
when x has the values -1, 1, 2, 3, respectively. Hence find f(0).
SOURCE CODDING
# Python3 program for implementing
# Newton divided difference formula
return sum;
for i in range(n):
for j in range(n - i):
print(round(y[i][j], 4), "\t",
end = " ");
print("");
# Driver Code
# value to be interpolated
value = 0;
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
2. The observed values of a function are respectively 168, 120, 72 and 63 at the four positions 3,
7, 9 and 10 of the independent variable. What is the best estimated value of the function at the
position 6 of the independent variable?
SOURCE CODDING
# Python3 program for implementing
# Newton divided difference formula
sum = y[0][0];
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
for i in range(1, n):
sum = sum + (proterm(i, value, x) * y[0][i]);
return sum;
for i in range(n):
for j in range(n - i):
print(round(y[i][j], 4), "\t",
end = " ");
print("");
# Driver Code
# value to be interpolated
value = 6;
# value to be interpolated
value = 6;
OUTPUT
3. Construct the Newton Divided Difference Table for generating Newton interpolation
polynomial with the following data set:
xi yi = f(xi)
0 0
1 1
2 8
3 27
4 64
SOURCE CODDING
# Python3 program for implementing
# Newton divided difference formula
sum = y[0][0];
return sum;
for i in range(n):
for j in range(n - i):
print(round(y[i][j], 4), "\t",
end = " ");
print("");
# Driver Code
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67
Determine the value of the velocity at t = 16 seconds using first order polynomial interpolation.
SOURCE CODDING
# divided difference table
return y;
sum = y[0][0];
return sum;
# difference table
for i in range(n):
# Driver Code
n = 6;
for j in range(10)];
y[0][0] = 0;
y[1][0] = 227.04;
y[2][0] = 362.78;
y[3][0] = 517.35;
y[4][0] = 602.97;
y[5][0] = 901.67;
y=dividedDiffTable(x, y, n);
printDiffTable(y, n);
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
# value to be interpolated
value = 16;
OUTPUT
Question 8:
(a)Implement the following using Gauss’s forward interpolation formula.
SOURCE CODDING
# Python3 code for Gauss's Forward Formula
# importing library
import numpy as np
temp = p;
for i in range(1, n):
if(i%2==1):
temp * (p - i)
else:
temp * (p + i)
return temp;
# function for factorial
def fact(n):
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
f=1
for i in range(2, n + 1):
f *= i
return f
# implementing Formula
sum = y[int(n/2)][0];
p = (value - x[int(n/2)]) / (x[1] - x[0])
for i in range(1,n):
# print(y[int((n-i)/2)][i])
sum = sum + (p_cal(p, i) * y[int((n-i)/2)][i]) / fact(i)
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
OUTPUT
SOURCE CODDING
import numpy as np
temp = p;
for i in range(1, n):
if(i%2==1):
temp * (p - i)
else:
temp * (p + i)
return temp;
# function for factorial
def fact(n):
f=1
for i in range(2, n + 1):
f *= i
return f
for i in range(1,n):
# print(y[int((n-i)/2)][i])
sum = sum + (p_cal(p, i) * y[int((n-i)/2)][i]) / fact(i)
CODDING
// CPP Program to interpolate using
// newton backward interpolation
#include <bits/stdc++.h>
using namespace std;
int main()
{
// number of values given
int n = 4;
float x[] = { 21, 25, 29,
33};
// Value to interpolate at
float value = 27;
cout << "\n Value at " << value << " is "
<< sum << endl;
return 0;
}
OUTPUT
Question 9:
(a)Implement the following using Stirling’s central difference interpolation formula.
1. Evaluate f(1.22) from the following table.
x 1.0 1.1 1.2 1.3
SOURCE CODDING
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
# Python3 program for implementing
# Newton divided difference formula
return sum;
for i in range(n):
for j in range(n - i):
print(round(y[i][j], 4), "\t",
end = " ");
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
print("");
# Driver Code
# value to be interpolated
value = 1.22;
SOURCE CODDING
import math
y1 = 0; N1 = 1; d = 1;
N2 = 1; d2 = 1;
temp1 = 1; temp2 = 1;
k = 1; l = 1;
delta = [[0 for i in range(n)]
for j in range(n)];
h = x[1] - x[0];
s = [Link](n / 2);
a = x[s];
u = (x1 - a) / h;
# Driver Code
n = 5;
x = [10, 11, 12, 13, 14 ];
fx = [ 23968, 28060, 31788, 35200, 38368];
CODDING
temp = p;
for i in range(1, n):
if(i%2==1):
temp * (p - i)
else:
temp * (p + i)
return temp;
# function for factorial
def fact(n):
f=1
for i in range(2, n + 1):
f *= i
return f
# implementing Formula
sum = y[int(n/2)][0];
p = (value - x[int(n/2)]) / (x[1] - x[0])
for i in range(1,n):
# print(y[int((n-i)/2)][i])
sum = sum + (p_cal(p, i) * y[int((n-i)/2)][i]) / fact(i)
Question 10:
(a)Implement the following using Everett’s interpolation.
1. Complete the following table and find f(1.7489).
SOURCE CODDING
#include<stdio.h>
main()
{
float x[100],y[100],a,s=1,t=1,k=0;
int n,i,j,d=1;
printf("\n\n Enter the number of the terms of the
table: ");
scanf("%d",&n);
printf("\n\n Enter the respective values of the
variables x and y: \n");
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
for(i=0; i<n; i++)
{
scanf ("%f",&x[i]);
scanf("%f",&y[i]);
}
printf("\n\n The table you entered is as follows
:\n\n");
for(i=0; i<n; i++)
{
printf("%0.3f\t%0.3f",x[i],y[i]);
printf("\n");
}
while(d==1)
{
printf(" \n\n\n Enter the value of the x to find the
respective value of y\n\n\n");
scanf("%f",&a);
for(i=0; i<n; i++)
{
s=1;
t=1;
for(j=0; j<n; j++)
{
if(j!=i)
{
s=s*(a-x[j]);
t=t*(x[i]-x[j]);
}
}
k=k+((s/t)*y[i]);
}
printf("\n\n The respective value of the variable y
is: %f",k);
printf("\n\n Do you want to continue?\n\n Press 1
to continue and any other key to exit");
scanf("%d",&d);
}
}
OUTPUT
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
float temp = u;
for (int i = 1; i <= n / 2; i++)
temp = temp * (u - i);
return temp;
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
}
int main()
{
// Number of values given
int n = 4;
float x[] = {20, 24, 28, 32};
// value to interpolate at
float value = 25;
cout << "Value at " << value << " is " << sum
<< endl;
return 0;
}
OUTPUT
17.541
Y=ex 10.240012.345215.2312 19.3499
2
SOURCE CODDING
#include <bits/stdc++.h>
using namespace std;
float temp = u;
for (int i = 1; i <= n / 2; i++)
temp = temp * (u - i);
return temp;
}
return f;
}
int main()
{
// Number of values given
int n = 5;
float x[] = {1.0, 1.5, 2.0, 2.5,3.0};
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
// y[][] is used for difference table
// with y[][0] used for input
float y[n][n];
y[0][0] = 10.2400;
y[1][0] = 12.3452;
y[2][0] = 15.2312;
y[3][0] = 17.5412;
y[4][0] = 19.3499;
// value to interpolate at
float value = 1.55;
return 0;
}
OUTPUT
X 20 25 30 35 40
Question 11:
(a)Implement the following using newton’s interpolation formula.
dy
1. Find at x= 1.5 from the following data.
dx
X 1.5 2.0 2.5 3.0 3.5 4.0
SOURCE CODDING
x=[1.5 2.0 2.5 3.0 3.5 4.0]; % inputting values of x
fx=[3.375 8.0 13.625 24.0 38.875 59]; % inputting values of y
dt=zeros(6,10); % function
for i=1:6 dt(i,1)=x(i);% for loop
dt(i,2)=fx(i); % calling function
end
n=5; % number of iterations
for j=3:10
for i=1:n
dt(i,j)=dt(i+1,j-1)-dt(i,j-1)
end
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
n=n-1;
end
h=x(2)-x(1) % finding the value of h
xp=1.5; % defining the value of xp
for i=1:5
q=(xp-x(i))/h; % calculating number of intervals
if (q>0&&q<1)
p=q;
end
end
p
l=xp-(p*h)
for i=1:5
if(l==x(i))
r=i;
end
end % calculating different value of y
f0=fx(r);
f01=dt(r,3);
f02=dt(r,(3+1));
f03=dt((r),(3+2));
f04=dt((r),(3+3));
% using the forward interpolation formula
fp=(f0)+((p*f01)+(p*(p-1)*f02)/(2)) + ((p*(p-1)*(p-2)*f03)/(6))+((p*(p-1)*(p-2)*(p-3)*f04)/(24))
OUTPUT:
fp =-50.2500
dy
[Link] at x= 45 from the following data using newton’s interpolation formula.
dx
X 20 25 30 35 40 45
SOURCE CODDING
x=[20 25 30 35 40 45]; % inputting the values of x
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
fx=[354332 291 260 231 204]; % inputting the value of y
dt=zeros(6,7); % declaring function
for i=1:6 % stating loop
dt(i,1)=x(i);
dt(i,2)=fx(i);
end
n=5;
for j=3:7
for i=1:n % using for loop
dt(i,j)=dt(i+1,j-1)-dt(i,j-1) % defining dt
end n=n-1;
end
h=x(2)-x(1) % finding the value of h
xp=27; % defining xp
for i=1:6
q=(xp-x(i))/h;
if (q>0&&q<1)
p=q;
end
end
p
l=xp-(p*h)
for i=1:6
if(l==x(i))
r=i;
end
end
% finding different value of y
f0=fx(r);
f01=dt((r-1),3);
f02=dt((r-2),(3+1));
f03=dt((r-3),(3+2));
f04=dt((r-4),(3+3));
%using backward difference formula
fp=(f0)+((p*f01)+(p*(p+1)*f02)/(2)) + ((p*(p+1)*(p+2)*f03)/(6))
OUTPUT:
fp=-4.800
3. The distance covered by athlete for the 50-meter race is given in the following table:
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
X 0 1 2 3 4 5
SOURCE CODDING
x=[0 1 2 3 4 5]; % inputting the values of x
fx=[0 2.5 8.5 15.5 24.5 36.5]; % inputting the value of y
dt=zeros(6,7); % declaring function
for i=1:6 % stating loop
dt(i,1)=x(i);
dt(i,2)=fx(i);
end
n=5;
for j=3:7
for i=1:n % using for loop
dt(i,j)=dt(i+1,j-1)-dt(i,j-1) % defining dt
end n=n-1;
end
h=x(2)-x(1) % finding the value of h
xp=27; % defining xp
for i=1:6
q=(xp-x(i))/h;
if (q>0&&q<1)
p=q;
end
end
p
l=xp-(p*h)
for i=1:6
if(l==x(i))
r=i;
end
end
% finding different value of y
f0=fx(r);
f01=dt((r-1),3);
f02=dt((r-2),(3+1));
f03=dt((r-3),(3+2));
f04=dt((r-4),(3+3));
%using backward difference formula
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
fp=(f0)+((p*f01)+(p*(p+1)*f02)/(2)) + ((p*(p+1)*(p+2)*f03)/(6))
OUTPUT
13.8333
4. A slider in machine moves along a fixed straight rod. Its distance x(in cm) along the rod is given
at various time t(in secs).
dy
Evaluate at t=0.1 and t=0.5.
dx
SOURCE CODDING
%Newton’s Backward Difference Formula MATLAB Program
x=[0 0.1 0.2 0.3 0.4 0.5 0.6]; % inputting the values of x
fx=[30.28 31.43 32.98 33.54 33.97 33.48 32.13]; % inputting the value of y
dt=zeros(6,7); % declaring function
for i=1:6 % stating loop
dt(i,1)=x(i);
dt(i,2)=fx(i);
end
n=5;
for j=3:7
for i=1:n % using for loop
dt(i,j)=dt(i+1,j-1)-dt(i,j-1) % defining dt
end n=n-1;
end
h=x(2)-x(1) % finding the value of h
xp=27; % defining xp
for i=1:6
q=(xp-x(i))/h;
if (q>0&&q<1)
p=q;
end
end
p
l=xp-(p*h)
for i=1:6
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
if(l==x(i))
r=i;
end
end
% finding different value of y
f0=fx(r);
f01=dt((r-1),3);
f02=dt((r-2),(3+1));
f03=dt((r-3),(3+2));
f04=dt((r-4),(3+3));
%using backward difference formula
fp=(f0)+((p*f01)+(p*(p+1)*f02)/(2)) + ((p*(p+1)*(p+2)*f03)/(6))
OUTPUT:
-16.25
Question 12:
Implement the following using Stirling’s interpolation formula and Bessel’s formula.
1. The distance covered by an athlete for the 50-metre race is given in the following table:
Time (sec) 0 1 2 3 4 5 6
SOURCE CODDING
# formula
return 1;
temp = u;
return temp;
# calculating factorial of
# given number n
def fact(n):
f = 1;
f *= i;
return f;
n = 7;
for j in range(n)];
Distance[0][0] = 0;
Distance[1][0] = 2.5;
Distance[2][0] = 8.5;
Distance[3][0] = 15.5;
Distance[4][0] = 24.5;
Distance[5][0] = 36.5;
Distance[6][0] = 50;
# difference table
# difference table
for i in range(n):
print("");
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
# value to interpolate at
value = 3.3;
k = 0;
k = int(n / 2);
else:
if (i % 2):
ucal(u, i - 1) *
Distance[k][i]) / fact(i);
else:
k -= 1;
OUTPUT:
2. From the following table of values of x and y, obtain dy/dx and d 2y/dx2 for x=1.7.
SOURCE CODDING
# formula
if (n == 0):
return 1;
temp = u;
return temp;
# calculating factorial of
# given number n
def fact(n):
f = 1;
f *= i;
return f;
n = 7;
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
x = [1.0, 1.2, 1.4, 1.6, 1.8, 2.0,2.2];
for j in range(n)];
y[0][0] = 2.7183;
y[1][0] = 3.3201;
y[2][0] = 4.0552;
y[3][0] = 4.9530;
y[4][0] = 6.0496;
y[5][0] = 7.3891;
y[6][0] = 9.0250;
# difference table
# difference table
for i in range(n):
# value to interpolate at
value = 1.7;
k = 0;
k = int(n / 2);
else:
if (i % 2):
ucal(u, i - 1) *
y[k][i]) / fact(i);
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
else:
k -= 1;
OUTPUT
SOURCE CODDING
# formula
if (n == 0):
return 1;
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
temp = u;
return temp;
# calculating factorial of
# given number n
def fact(n):
f = 1;
f *= i;
return f;
n = 7;
x = [7.47,7.48, 7.49,7.50,7.51,7.51,7.52];
for j in range(n)];
y[0][0] =0.193;
y[1][0] = 0.195;
y[2][0] = 0.198;
y[3][0] = 0.201;
y[4][0] = 0.203;
y[5][0] = 0.206;
y[6][0] = 0.208;
# difference table
# difference table
for i in range(n):
print("");
# value to interpolate at
value = 7.5;
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
# Initializing u and sum
k = 0;
k = int(n / 2);
else:
if (i % 2):
ucal(u, i - 1) *
y[k][i]) / fact(i);
else:
k -= 1;
OUTPUT:
4. Find f’(28) given that y20 = 48234, y25 = 47354, y30 = 44978 and y35 = 43389.
SOURCE CODDING
# Approximation
import math
# Stirling formula
y1 = 0; N1 = 1; d = 1;
N2 = 1; d2 = 1;
temp1 = 1; temp2 = 1;
k = 1; l = 1;
for j in range(n)];
h = x[1] - x[0];
s = [Link](n / 2);
a = x[s];
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
u = (x1 - a) / h;
# table
delta[j][i - 1]);
y1 = fx[s];
if (i % 2 != 0):
if (k != 2):
else:
k += 1;
d *= i;
s = [Link]((n - i) / 2);
l += 1;
d *= i;
s = [Link]((n - i) / 2);
print(round(y1, 3));
# Driver Code
n = 4;
x1 = 28;
OUTPUT:
Question 13:
Implement the following using Numerical Differentiation using Lagrange’s Interpolation.
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
[Link] from following table the value of the derivative of y = f(x) at
SOURCE CODDING
# Lagrange Interpolation
# Importing NumPy Library
import numpy as np
p=1
for j in range(n):
if i != j:
p = p * (xp - x[j])/(x[i] - x[j])
yp = yp + p * y[i]
# Displaying output
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
print('Interpolated value at %.3f is %.3f.' % (xp, yp))
OUTPUT:
[Link] from following table the value of the derivative of y=f(x) at x=1.7489.
SOURCE CODDING
# Lagrange Interpolation
# Importing NumPy Library
import numpy as np
for i in range(n):
p=1
for j in range(n):
if i != j:
p = p * (xp - x[j])/(x[i] - x[j])
yp = yp + p * y[i]
# Displaying output
[Link] the value of y’ at x = 0 given some set of values (-2, 5), (1, 7), (3, 11), (7, 34)?
SOURCE CODDING
# Lagrange Interpolation
# Importing NumPy Library
import numpy as np
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
# Reading number of unknowns
n = int(input('Enter number of data points: '))
p=1
for j in range(n):
if i != j:
p = p * (xp - x[j])/(x[i] - x[j])
yp = yp + p * y[i]
# Displaying output
print('Interpolated value at %.3f is %.3f.' % (xp, yp))
OUTPUT:
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
Question 14:
Implement the following using trapezoidal rule.
∫ √1+ x 2 dx
1
Source Code:
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define f(x) (√(1+x^2 ))
Output:
SOURCE CODDING.
#include<iostream>
#include<cmath>
using namespace std;
float mathFunc(float x) {
return (exp(-x));
}
main() {
float result, lowLim, upLim;
int interval;
cout << "Enter Lower Limit, Upper Limit and interval: "; cin >>lowLim >>upLim >>interval;
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
result = integrate(lowLim, upLim, interval);
cout << "The answer is: " << result;
}
OUTPUT:
3. A solid of revolution is formed by rotating about x-axis, the area between x-axis,
the line and a curve through the points with the following coordinates:
Estimate the volume of solid formed, giving the answer up to 3 decimal places.
Question 15:
Implement the following using Simpson’s 1/3rd Rule and 3/8 rule.
1. Find the approximate value of x and the distance covered by a rocket from t=8 to t=30 is given by
30
140000
x 2000 ln 9.8t dt
8 140000 2100t
SOURCE CODDING
return (float)[Link](x);
int n)
float h = (b - a) / n;
// and f(x)
x[i] = ((b-a/6)*(f(8)+4*(f(19))+f(30)));
fx[i] = func(x[i]);
// Calculating result
float res = 0;
if (i == 0 || i == n)
res += fx[i];
else if (i % 2 != 0)
res += 4 * fx[i];
else
res += 2 * fx[i];
return res;
}
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
// Driver Code
// Lower limit
float lower_limit = 8;
// Upper limit
// Number of interval
int n = 4;
[Link](simpsons_(lower_limit,
upper_limit, n));
OUTPUT
//1106.72
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
2. A company advertises that every roll of toilet paper has at least 250 sheets. The probability that
there are 250 or more sheets in the toilet paper is given by:
P y 250 0.3515 e 0.3881 y 252.2 dy
2
250
SOURCE CODDING
return (float)[Link](x);
int n)
// and f(x)
x[i] = a + i * h;
fx[i] = func(x[i]);
// Calculating result
float res = 0;
if (i == 0 || i == n)
res += fx[i];
else if (i % 2 != 0)
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
res += 4 * fx[i];
else
res += 2 * fx[i];
return res;
// Driver Code
// Lower limit
// Upper limit
// Number of interval
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
int n = 4;
[Link](simpsons_(lower_limit,
upper_limit, n));
OUTPUT
2 0.17907
4 0.20133
6 1.0090
8 1.2042
10 1.0954
Question 16:
(a) Implement the following using Richardson Extrapolation
1. Evaluate numerically the derivative of
SOURCE CODDING
for I in range(k):
L[I][0]=D(func,a,1/(2**(I+1)))
for j in range(1,k):
for i in range(k-j):
L[i][j]=((4**(j))*L[i+1][j-1]-L[i][j-1])/(4**(j)-1)
return L[0][k-1]
OUTPUT:
1.09
-2.23
8
I =∫ (−0.055 x 4+ 0.86 x3 −4.2 x 2+6.3 x +2)dx
0
SOURCE CODDING
import [Link];
import static [Link];
public class richardinte {
static double fun(float x)
{
double temp = -0.055*[Link](x,4)+0.8*[Link](x,3)-
4.2*[Link](x,2)+6.3*x+2;
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
return temp;
}
public static void main(String[]args)
{
Scanner in=new Scanner([Link]);
[Link]("Write lower limit a and upper limit b:");
float a = [Link]();
float b = [Link]();
[Link]("Write four subintervals: ");
float[] n=new float[4];
double[] av=new double[4];
float n1 = [Link]();
float n2 = [Link]();
float n3 = [Link]();
float n4 = [Link]();
float h=0;
h=(b-a)/n1;
double sum=0;
sum=fun(a)+fun(b);
for (int i=1; i<n1; i++)
{sum +=2*fun(a+i);
}
double result1 =sum*h/2;
h=(b-a)/n2;
double sum2=0;
sum2=fun(a)+fun(b);
for (int i=1; i<n2; i++){
sum2 +=2*fun(a+i);
}
double result2 =sum2*h/2;
h=(b-a)/n3;
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
double sum3=0;
sum3=fun(a)+fun(b);
for (int i=1; i<n3; i++)
{sum3 +=2*fun(a+i);
}
double result3 =sum3*h/2;
h=(b-a)/n4;
double sum4=0;
sum4=fun(a)+fun(b);
for (int i=1; i<n4; i++)
{sum4 +=2*fun(a+i);
}
double result4 =sum4*h/2;
double tv=2000*[Link](b)-((2000*[Link](b)*14000)/2100)*[Link](b)-
(9.8/2)*b*b;
if(tv<result1 || tv==result1)
{
[Link]("True Value of the given function is "+round(tv,3)+"\n Which is
very close to actual value"+round(result1,3));
}
else if(tv<result2 || tv==result2)
{
[Link]("True Value of the given function is "+round(tv,3)+"\n Which is
very close to actual value"+round(result2,3));
}
else if(tv<result3 || tv==result3)
{
[Link]("True Value of the given function is "+round(tv,3)+"\n Which is
very close to actual value"+round(result3,3));
}
else if(tv<result4 || tv==result4)
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018
{
[Link]("True Value of the given function is "+round(tv,3)+"\n Which is
very close to actual value"+round(result4,3));
}
}}
OUTPUT:
3.0
Dist(m) 0 1 2 2.5 3 4
Use Richardson extrapolation method to obtain the highest accurate value of estimating the speed at
t=0.2 seconds.
JINNAH UNIVERSITY FOR WOMEN
DEPARTMENT of COMPUTER SCIENCE & SOFTWARE ENGINEERING
LAB ASSIGNMENT
SOHEERA JADOON
23004
BSSE 2018