Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. write a function of c program to return the vector-vector product of two vect

ID: 3722584 • Letter: 1

Question

1. write a function of c program to return the vector-vector product of two vectors:

a^T * b

where a^T = a transpose

function prototype is given as: float vector_vector_multiply (float a[], float b[], int n);

2. write a function of c program to store in vector b the reverse of vector a (elements of b should be the elements of a in reverse order)

function prototype: void reverse (float a[], float b[], int n);

3. write a function of c program to compute the matrix vector product:

c = Ab

where A is a n x n matrix, and b and c are n x 1 vectors

function prototype: void matrix_vector_product (float a[][SIZE], float b[], float c[], int n);

Explanation / Answer

float vector_vector_multiply (float a[], float b[], int n)
{
float transpose[10], mul[10];
int i,j=10;
for(i=0;i<10;i++)
{
a[i]=transpose[j];
j--;
}

for(i=0;i<10;i++)
{
mul[i]=transpose[i]*b[i];
}

}

2.
void reverse (float a[], float b[], int n)
{
int i, j=n;
for(i=0;i<n;i++)
{
a[i]=b[j];
j--;
}
}

3.
#include<stdio.h>
main()
{
int i,j,k,r1,c1,r2,c2,a[10][10],b[10][10],c[10][10];
printf("Enter the no. of rows and columns of matrix 1 : ");
scanf("%d%d",&r1,&c1);
printf("Enter the no. of rows and columns of matrix 2 : ");
scanf("%d%d",&r2,&c2);
if(c1==r2)
{
printf("Enter the matrix 1 ");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the matrix 2 ");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<r1;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("Product of matrices ");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
printf("%d ",c[i][j]);
}
printf(" ");
}
}
else
printf("Matrix multiplication not possible");
printf(" ");
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote