Math Projeact280

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering
Semester: (Spring, Year:2024), B.Sc. in CSE (Day)

Course Title: Linear Algebra and Vector Analysis


Course Code: MAT 103 Section:D5

Student Details

Name ID
1. Rukonuzzaman Topu 232002280

Submission Date : 3/31/2024


Course Teacher’s Name : Jakia Sultana

[For Teachers use only: Don’t Write Anything inside this box]

Lab Report Status


Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................
Code 1:
#include<stdio.h>
void solution( int a[][20], int var );
int main()
{
int a[ 20 ][ 20 ], var, i, j, k, l, n;
printf( "\nEnter the number of variables: " );
scanf( "%d", &var );
for ( i = 0;i < var;i++ )
{
printf( "\nFor equation %d,\n", i + 1 );
for ( j = 0;j < var;j++ )
{
printf( "Enter the coefficient of x%d: ", j + 1 );
scanf( "%d", &a[ i ][ j ] );
}
printf( "\nEnter the constant: " );
scanf( "%d", &a[ i ][ var] );
}
solution( a, var );
return 0;
}
void solution( int a[ 20 ][ 20 ], int var )
{
int k, i, l, j;
for ( k = 0;k < var;k++ )
{
for ( i = 0;i <= var;i++ )
{
l = a[ i ][ k ];
for ( j = 0;j <= var;j++ )
{
if ( i != k )
a[i][j] = (a[k][k]*a[i][j])-(l*a[k][j]);
}
}
}
printf( "\nSolutions:" );
for ( i = 0;i < var;i++ )
{
printf( "\nTHE VALUE OF a%d = %.2f\n", i + 0, ( float )
a[ i ][ var ] / ( float ) a[ i ][ i ] );
}
}
Output 1:

Comments :
I used C programming language to solve this. It was slightly
challenging at first because of the matrix format. I used array , for
loop to solve this.
Code 2:
#include <stdio.h>
int main() {
int ar[11][1][2] = {
{{4, 15}},
{{0, 25}},
{{15, 21}},
{{18, 19}},
{{5, 12}},
{{6, 0}},
{{16, 5}},
{{18, 6}},
{{5, 3}},
{{20,12}},
{{25,0}}
};
int mat[2][2] = {
{1, 2},
{1, 3}
};
int result[11][2];
for (int i = 0; i < 11; i++) {
for (int j = 0; j < 1; j++) {
for (int k = 0; k < 2; k++) {
int sum = 0;
for (int l = 0; l < 2; l++) {
sum += mat[k][l] * ar[i][j][l];
}
result[i][k] = sum;
}
}
}
printf("Encoded message:\n\n");
for (int i = 0; i < 11; i++) {
for (int j = 0; j < 2; j++) {
printf("%d ", result[i][j]);
}
}
printf("\n");
return 0;
}
Comment :
Here i used C language to solve this. I took “Do Yourself Perfectly” as
Encoded Message. Here i used array and loops to solve the problem.
Code 3:
#include <stdio.h>
#include <stdlib.h>

// Function to perform Gaussian elimination


void gaussElimination(float matrix[][3], int n) {
int i, j, k;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
float f = matrix[j][i] / matrix[i][i];
for (k = 0; k <= n; k++) {
matrix[j][k] -= f * matrix[i][k];
}
}
}
}

// Function to perform back substitution


void backSubstitution(float matrix[][3], int n, float *result) {
int i, j;
for (i = n - 1; i >= 0; i--) {
result[i] = matrix[i][n];
for (j = i + 1; j < n; j++) {
result[i] -= matrix[i][j] * result[j];
}
result[i] /= matrix[i][i];
}
}

int main() {
// Coefficients of the equations
float coefficients[2][3] = {{10, 6, 90}, {3, 5, 70}};

// Perform Gaussian elimination


gaussElimination(coefficients, 2);

// Back substitution to find the solution


float solution[2];
backSubstitution(coefficients, 2, solution);

if(solution[0]>=0.85 && solution[0]<=1.10){


printf("Number of children: 1\n");}
else{
int s0=solution[0];
printf("Number of children: %d\n",s0);
}
int s1= solution[1];
printf("Number of adults: %d\n",s1);

return 0;
}

Out put 3:

Comments : This Problem was challenging to solve, This program


solves the system of linear equations using Gaussian elimination
followed by back substitution. It will output the number of children and
adults in the group.

You might also like