0% found this document useful (0 votes)
57 views9 pages

BCSL-058 (2022-23) Solved Assignment

This document contains 5 questions asking students to write programs in C or C++ to solve various numerical problems. Question 1 asks to solve a system of linear equations using Gaussian elimination. Question 2 asks to calculate a definite integral using Simpson's 1/3 rule. Question 3 asks to demonstrate forward and central difference operators. Question 4 asks to find the value of Sin(u/6) using Lagrange interpolation. Question 5 asks to calculate the value of cos x using a Taylor series expansion up to 3 terms and compare to the inbuilt function. The document provides details needed to solve each problem, like the equations, integration limits, function definitions and sample data points.

Uploaded by

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

BCSL-058 (2022-23) Solved Assignment

This document contains 5 questions asking students to write programs in C or C++ to solve various numerical problems. Question 1 asks to solve a system of linear equations using Gaussian elimination. Question 2 asks to calculate a definite integral using Simpson's 1/3 rule. Question 3 asks to demonstrate forward and central difference operators. Question 4 asks to find the value of Sin(u/6) using Lagrange interpolation. Question 5 asks to calculate the value of cos x using a Taylor series expansion up to 3 terms and compare to the inbuilt function. The document provides details needed to solve each problem, like the equations, integration limits, function definitions and sample data points.

Uploaded by

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

wwuv.ignousite.

com
Course Code : BŒL-058
Course Tltle : Computer orîented Numerlcal techniques Lab
Assignment Number : BCA(5)/L-058/Assignment/2022-23
Maximum Marks : id
Weightage : 25% vn/nv.lgnouske.com
Last Dates for Submlsslon : 31" October, 2022 (For July Session ••.•••@
: 15’ April. 2023 (fior January Session)
h

Q1. Write a program in CXC++ to find the solution of system of linear equations (given (8)
bclcw), by using Gaus‘x‘- Elimination methud:

z + y -F r = 2
x 2 y + 3a = 14

Q2. Writc a program in CXC++ to dctcrminc thc approximatc value ot thc definite intcpral (8)
(I) (given below), by usizig Siozpsoz's (J/3)rd mle:
1.D
I= x ’* 3 dx,

Using step si'ze (h,) = 0.2


Q3. Write a program in C or C++ to demonstrate the following operations, for die (8)
funcGwn {(x) = x' +x + 7 :

(n) Forward DiffereDCe Operator


fb) Central Difference Operator

Q4. Write :t program in C/C++ to find the value of Sin(u/6) by using Lagrange's (8)
Interpolaiion, the related date is given below

0 z/4
y= Sin(x) 0 0.70711 1.0

Q5. Write a program in C/C to cnlcul tc the valuc of “cos z” by owing thc series (8)
expansion %ven below:
O0S/= 1--
2!+ + ...
4! 8!

Note: Evaluate cus x only upto first three terms.


A he F›nd the value of cosz by using the inbuilt function.
Compare the rcsutt : 1.e., the wxu!£ produced by your prngmm snd thst produced by

inbuilt function, gasod nn ccimparison. determinc error.

Ignou Study HeJpewSuniJ Poonia Page 1


wwuv.ignousite.com
Ans.1
#incIude <stdio.h>
#include <stdIib.h>
#incIude <math.h>
Tnt main()
a e
int n,i,j,k; @
float a[10][10]=(0.01. x[10l=(0.0Ti
float pivot = 0.0;
float factor = 0.0;
float sum = 0.0;
printf("Gauss Elimination \n\n");
printf("Enter number of equations:");
scanf("9¢d",&n)•
printf(“%d\n“,n);
printf(“\n\I Input Coefficients a[i, j+1], row-wise\n");
for(i=1;i<=n;i++)

for(j=11<=n+1;j++)

••a•*(°•¢*',^a[ill?]):

for(i=1;i<=n;i-i-+)

for(j=1;j<=n+1;j++)

printf("\t9L10.0f",a[i]|j]);

printf(“\n\n");

for(k=1;k<=n-1;k++)

if(a[k] k)==O.0)

printf("error“);

pivot = a[kjlkl;
for(j=k;j<=n+1;j++)
a[k]§]= a|k) §j/pivot;
for(i=k+1;i<=n;i++)

łgnou Study HełpewSunił Page


factor = a|i][k];
for(j = k;j<=n+1;j++)

a[i]|j] = a[i][j] - factor ” a[k]g]:


)

if(a[n][n]= =O) **•‘^’°


printf(“error“);
else

x[n] = a[n][n+ 1]/« [«Hol:

for(i-n-1;i>=1;i--)

sum = 0.0;
for(j=i+1;j•:=n;i**)
Sum = sum + a|ijȘj ” x|j];
[/]- ( [i]l +1] • )/ [i][il:

for(i=1;i<=n;i++)

printf("\n\tx %1d]=9610.4f“,i,x(i));

system("PAUSE”);
return 0;

Ignou Study Hetper-Sunil Pag


wwuv.ignousite.com
Ans.1
#incIude<stdio.h»
#incIude<conio.h>
float f(fIoat x)

return(1/ț1+x});

void main()

i nt i,n;
float x0,xn,h,y[20],so,se,ans,x[20]; printf("\
n Enter values of x0,xn, h: ");
scanf("96f96f%f‘,&X0,&xn,&h);
n=(xn-x0}/h;
if(n%2==1)

h=(xn-x0)/n;
printf("\n Refined value of n and h are:Kd %f\n",n.h);
printf("\n Y values: \n"j;
for(i=0; i<=n, i++)

x[i]=xD+i”h;

printf("\n %f\n”,y[i]);

sol;
se=0;
for(i=1; i<n; i++)

if(i%2==1)

else

se=se+y[i];

ans=h/3*(y[0]+y(n]+4*so+2‘se);
printf("\n Final integration ts %f",ans);
getch();

Ignou Study Heîper-Suniî Poonia Pagc 4


Ans.3 {a)
forward.c
#include<conio.h>
#include<stdio.h>
#dufine F(x) (x)*(x) + (x) + 7 //FUNCTION F(X)
void main()
(
int n;
float a,b,h,x;
double f1,f2,f0,FWDOP,BWDOP,CDOP,AVGOP;
/”FWDOP — FORWARD DIFFERENCE OPERATOR’/
cIrscr\);
printf("\n Enter the interval (a,b)");
printf("\nEnter the value of a: "j;
scanf{“P f",&a);
printf("\nEnter the value of b: ");
scanf("%f",&b);
printf(”\nEnter the number of nodes(n) In the interval {a,b): ");
scanf{"sâd”,&n);
h=(b-a)/n; //STEP SIZE CALCULATION
printf(“\n5TEP SIZE (h) =: Kf“,h);
printf("\n VALUE OF POINT OF EVALUATION (X) :");
scanf f"%f",&x}:
FWDOP = F(x+h) - F(x);
printf(“\n RESULT OF FORWARD DIFFERENCE OPEATOR = Kf“,FWDOP);
getch();

Ignou Study Helper-Sunil Pap


Ans.3 (b) central.c
include<conio.h»
#inClude< stdio.h>
/tdefine F(x) (x)”(x) + (x) + 7 //FLT NCTION F(X)
void main()

int n;
float a,b,h,x;
double f1,fZ,f0,FWDOp,BWDOP,CDOP,AVGOP;
/” CDOP — CENTRAL OIFFERENCE OPFRATOR ’/
cIrscr(T;
printf(“\n Enter the interval (a,b)”);
printf("\nEnter the value of a: ");
scanf{"%f",&a l;
printf("\nEnter the value of b: ");
scanf{"%f",&b);
printf(“\nEnter the number of nodes(n) In the interval (a,b): ”);
scanf{"%d”.&n);
h={b-a)/n; //STEP SIZE CALCULATION
printf("\nSTEP SIZE (h) =: 9âf”,h);
printf("\n VALUE OF POINT OF EVALUATION (X) ! ");
‹» t('!o f",s T;
CDOP = F(x+(h/2 }\ — F(x—(h/2});
printf(”\n RESULT OF CENTRAL DiFFERENCE OPEATOR = %f”,CDOP);
getch();

Ignou Study Helper-Sunil Page


wwuv.ignousite.com
Output:-

Ans.4
#include <cmath>
#incIude <iostream»
dinclude <iomanip>
using namespace std;
#define PI 3.1415
/fdefine N 12
int main()

// Declare and initialize two arrays to hold the coordinates of the Initial data points
double x[Nj, y[N];
// Generate the points
double xx = PI, step = 4 * PI / (N - 1);
for (int i = 0; i < N, ++i, xx += stepj

y[i] = sin(2 * xx) / xx;

// Initialize the Lagrange interpolation routine with known data poinM


Maths::InterpoIation::Lsgrange A(N, x, y};
// Interrogate Lagrange polynomial to find interpolated values
i nt N_out = 20;
xx -- PI, step = (3 * PI) / (N out - 1);
for (int i = 0; i < N_out; ++I, xx += step) (
cout << "x = " << setw(7) << e << " y = ",
cout << setw(13) << A.getVaIue(xx, 3) << endl;

return 0;

Ignou Study Helper-Sunil Page


Ans.5

#incIude <bits/stdc++.h>
using namespace std;
const double PI = 3.142;
double cosXSertiesSum(double x, Int n)

x = x ” (PI / 180.0);
double res = 1;
double sign = 1, fact = 1,
pow = 1;
for (int i = 1; i < 5; i++)

sign = sign ” -1;


fact = fact ” (z * i - 1) * (2 i);
paw = pow * x ” x;
res = res+ sign ”
pow / fact;

return res;

// Driver Code
int main()

float x = 50;
Int n = 5;
cout << cosXSertiesSum(x, 5);
return 0;

Ignou Study HeJpewSuniJ Page


wwuv.ignousite.com

Ignou Study Helper-Sunil

You might also like