CBNST Lab
CBNST Lab
Term-Work
On
By
Shyam Yadav
20011180
Faculty-in-Charge
Shashi Kumar Sharma
Assistant Professor
I, …………….., hereby declare the work, which is being presented in the term-work, entitled
“CBNST LAB “ in partial fulfillment of the requirement for the award of the degree B,Tech in
the session 2022-2022, is an authentic record of my own work carried out under the supervision
The matter embodied in this term-work has not been submitted by me for the award of any other
degree.
Campus for the award of Bonafede work carried out by his/ her. He/She has worked under
my guidance and supervision and fulfilled the requirement for the submission of reports.
(…………………) (……………………)
#include<iostream>
using namespace std;
#include<math.h>
int main()
{
double abs_err, rel_err, p_rel_err, t_val, a_val;
cout<<"\n INPUT TRUE VALUE: ";
cin>>t_val;
cout<<"\n INPUT APPROXIMATE VALUE: ";
cin>>a_val;
abs_err = fabs(t_val-a_val);
rel_err = (abs_err / t_val);
p_rel_err = (rel_err * 100);
cout<<"\nABSOLUTE ERROR= "<< abs_err;
cout<<"\nRELATIVE ERROR= "<<rel_err;
cout<<"\nPERCENTAGE RELATIVE ERROR= "<< p_rel_err;
return 0;
}
PRACTICAL- 2
Objective- Write a program to find out the root of the Algebric and
Transcendental equations using Bisection Method.
#include<bits/stdc++.h>
using namespace std;
#define EPSILON 0.01
double func(double x)
{
return x*x*x - x*x + 2;
}
double c = a;
while ((b-a) >= EPSILON)
{
c = (a+b)/2;
if (func(c) == 0.0)
break;
else if (func(c)*func(a) < 0)
b = c;
else
a = c;
}
cout << "The value of root is : " << c;
}
int main()
{
double a, b;
cout<<"Enter the values: ";
cin>>a>>b;
bisection(a, b);
return 0;
}
PRACTICAL- 3
Objective- Write a program in to implement Newton’s Forward and
Backward Interpolation formula.
//forward
#include <bits/stdc++.h>
using namespace std;
float u_cal(float u, int n)
{
float temp = u;
for (int i = 1; i < n; i++)
temp = temp * (u - i);
return temp;
}
int fact(int n)
{
int f = 1;
for (int i = 2; i <= n; i++)
f *= i;
return f;
}
int main()
{
int n = 4;
float x[] = { 45, 50, 55, 60 };
float y[n][n];
y[0][0] = 0.7071;
y[1][0] = 0.7660;
y[2][0] = 0.8192;
y[3][0] = 0.8660;
for (int i = 1; i < n; i++)
{
for (int j = 0; j < n - i; j++)
y[j][i] = y[j + 1][i - 1] - y[j][i - 1];
}
cout << "\n Value at " << value << " is "
<< sum << endl;
return 0;
}
//Backward
#include <bits/stdc++.h>
using namespace std;
float u_cal(float u, int n)
{
float temp = u;
for (int i = 1; i < n; i++)
temp = temp * (u + i);
return temp;
}
int fact(int n)
{
int f = 1;
for (int i = 2; i <= n; i++)
f *= i;
return f;
}
int main()
{
int n = 5;
float x[] = { 1891, 1901, 1911,1921, 1931 };
float y[n][n];
y[0][0] = 46;
y[1][0] = 66;
y[2][0] = 81;
y[3][0] = 93;
y[4][0] = 101;
cout << "\n Value at " << value << " is " << sum << endl;
return 0;
}
PRACTICAL- 4
Objective- Write a program in to implement Gauss Forward and
Backward interpolation formula.
//Forward
#include <iostream>
using namespace std;
#include <math.h>
int main()
{
int n;
int i,j;
float ax[10];
float ay[10];
float x;
float nr,dr;
float y=0; float h;
float p;
float diff[20][20];
float y1,y2,y3,y4;
cin>>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<=4;j++)
{
for(i=0;i<n-j;i++)
{
diff[i][j]=diff[i+1][j-1]-diff[i][j-1];
}
}
i=0;
do
{
i++;
}
while(ax[i]<x);
i--;
p=(x-ax[i])/h;
y1=p*diff[i][1];
y2=p*(p-1)*diff[i-1][2]/2;
y3=(p+1)*p*(p-1)*diff[i-2][3]/6;
y4=(p+1)*p*(p-1)*(p-2)*diff[i-3][4]/24;
y=ay[i]+y1+y2+y3+y4;
cout<<"\nwhen x= "<<x<<"y="<<y;
return 0;
}
//Backward
#include <iostream>
using namespace std;
#include <math.h>
int main()
{
int n;
int i,j; float ax[10];
float ay[10];
float x;
float y=0;
float h;
float p;
float diff[20][20];
float y1,y2,y3,y4;
// Regular Falsi
#include <bits/stdc++.h>
using namespace std;
#define f(x) (x*x-2*x-5)
int main(){
cout << fixed << setprecision(5);
double a = 0, b = 4;
double y1, y2, x, y;
y1 = f(a);
y2 = f(b);
x = (a*y2-b*y1)/(y2-y1);
y = f(x);
int n=20;
while(n--){
if(y < 0){
a=x; y1=y;
}else if(y > eps){
b=x; y2=y;
}
// cout << a << " " << b << " " << y1 << " " << y2 << endl;
x = (a*y2-b*y1)/(y2-y1);
y = f(x);
}
cout << x << endl;
}