The computation of inner products and vector norms in C can be implemented using basic arithmetic operations and functions from the math.h library.
Linear Algebra
PROGRAMMES
IN PYTHON AND C LANGUAGES
UNIT − III:
INNER PRODUCT SPACES
COMPUTATION OF INNER
PRODUCTS AND VECTOR NORMS BY USING C
The
computation of inner products and vector norms in C can be implemented using
basic arithmetic operations and functions from the math.h library.
The
inner product of two vectors u = (u1, u2, ..., un)
and v = (v1, v2, ….vn) is defined as:
u.v = nΣi=1 uivi
= uivi + u2v2 + ... + unvn
A
C function to compute this can be implemented as follows:
C
#include <stdio.h>
double inner_product (double u[], double v[], int n)
{
double sum = 0.0;
for (int i=0; i < n; i++)
sum += u[i]*v[i];;
}
return sum;
}
int main() {
double u[]= {1.0, 2.0, 3.0};
double v[] = {4.0, 5.0, 6.0};
int n=3;
double result = inner_product (u, v,n);
printf("Inner product: %1f\n", result); // Expected: 32.0
return 0;
}
The
Euclidean norm of a vector v = (v1, v2,..., vn)
is defined as:

A
C function to compute this can be implemented as follows:
C
#include <stdio.h>
#include <math.h> // Required for sqrt()
double vector_norm (double v[], int n) {
double sum_sq = 0.0;
for (int i = 0;i<n;i++)) {
sum_sq+= v[i]*v[i];
}
return sqrt (sum_sq);
}
int main () {
double v[]= {3.0, 4.0);
int n =2;
double result = vector_norm (v, n);
printf("vector norm: %f\n", result); // Expected: 5.0
return 0;
}
• Arrays for vectors:
In C, vectors are typically represented using arrays of double (or float) to
store their components.
• Looping for
summation: Both inner product and norm calculations involve
summing up terms. A for loop iterates through the vector components, performing
the necessary multiplication and addition.
• sqrt() function:
The sqrt() function from the math.h library is used to calculate the square
root for the vector norm.
• Function parameters:
The functions take the vector arrays and their dimension (n) as parameters to
make them general and reusable.
Linear Algebra: Practice Programs in Python and C Languages : Tag: maths, mathematics : - Computation of Inner Products and Vector Norms by Using C (Linear Algebra: Inner Product Spaces)
Linear Algebra
MA25C02 2nd Semester | 2025 Regulation
English Essentials II
EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Tamils and Technology தமிழர்களும் தொழில்நுட்பமும்
UC25H02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Linear Algebra
MA25C02 2nd Semester | 2025 Regulation
Transforms and its Applications
MA25C03 2nd Semester EEE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Applied Physics (CE) II
PH25C02 2nd Semester Civil, Agri Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Applied Physics (CSIE) II
PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Applied Physics (EE) II
PH25C04 2nd Semester EEE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Applied Physics (ME) II
PH25C05 2nd Semester Mechanical Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Applied Chemistry (CE) II
CY25C02 2nd Semester Civil Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Applied Chemistry (ME) II
CY25C03 2nd Semester Mechanical Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Electron Devices
EC25C01 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Digital Principles and Computer Organization
CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electrical and Electronics Engineering
EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Civil and Mechanical Engineering
GE25C01 2nd Semester EEE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Data Structures using CPlusPlus
CS25C05 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Engineering Drawing
ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Data Structures and Algorithms
CS25C04 2nd Semester EEE Dept | 2025 Regulation
Circuits and Network Analysis
EC25C02 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Engineering Mechanics
ME25C02 2nd Semester Mech, Civil, Agri Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Object Oriented Programming (OOPs)
CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation