The question asks to write a program that computes the following:
{x}(n+1) = [K] {x}(n)+ {z}, n = 0,1,2,3,4.
In other words, the next vector {x} is equal to the product of [K] and
the current vector {x} + constant vector {z}.
[K] is a constant 3x3 matrix defined by:
double k[3][3] = { { 1.2, -3.0, 1.1},
{-4.1, 6.2, -2.2},
{ 3.4, -2.5, -3.3} };
The initial components of the vector {x}(0) are specified by:
double x[3] = { 1./sqrt(2.), 0., -1./sqrt(2.) },
while the constant vector {z} is:
double z[3] = { 1./sqrt(3.), -1./sqrt(3.), 1./sqrt(3.) }
so far i have everything done except i dont know how to account for adding the constant vector in [K] {x}(n)+ {z}, as the reader has nothing on it and i have very little experience with linear algebra [K] {x}(n)+ {z}.
can someone help me with this please? this is what i have thus far
#include <stdio.h>
#include <math.h>
void unit_norm(doubl e *vec, int cols);
void matrix_mult(dou ble a[3][3], double *b, double *c, int rows);
main()
{
int row, i, j;
double k[3][3] = {{1.2, -3.0, 1.1},
{-4.1, 6.2, -2.2},
{3.4, -2.5, -3.3}};
double y[3], x[3] = { 1./sqrt(2.), 0., -1./sqrt(2.) };
double w[3], z[3] = { 1./sqrt(3.), -1/sqrt(3.), 1./sqrt(3.) };
printf("\nIniti al vector:\n\n");
printf("x[0] = [");
for(row=0; row<3; row++)
printf(" %.6f ", x[row]);
printf("]\n\n");
for(i=0; i<=4; i++)
{
matrix_mult(k,x ,y,3);
printf("New Vector:\ny[%d] = [", i+1);
ifor(j=0; j<=2; j++)
printf(" %.6f ", y[j]);
printf("]\n");
unit_norm(y,3);
printf("Normali zed new vector:\nx[%d] = [", i+1);
for(j=0; j<=2; j++)
printf(" %.6f ", y[j]);
printf("]\n");
for(j=0; j<=2; j++)
x[j] = y[j];
printf("\n");
}
return(0);
}
void matrix_mult(dou ble a[3][3], double *b, double *c, int rows)
{
int k, s;
double dot_p;
for(s=0; s<rows; s++)
{
/* ......COMPUTATI ON.... */
/* THIS PORTION IS WHERE I AM HAVING THE PROBLEM */
}
return;
}
void unit_norm(doubl e *vec, int cols)
{
double norm;
double sum=0.;
int n;
for(n=0; n<cols; n++)
sum += vec[n] * vec[n];
sum = sqrt(sum);
for(n=0; n<cols; n++)
vec[n] = vec[n]/sum;
return;
}
{x}(n+1) = [K] {x}(n)+ {z}, n = 0,1,2,3,4.
In other words, the next vector {x} is equal to the product of [K] and
the current vector {x} + constant vector {z}.
[K] is a constant 3x3 matrix defined by:
double k[3][3] = { { 1.2, -3.0, 1.1},
{-4.1, 6.2, -2.2},
{ 3.4, -2.5, -3.3} };
The initial components of the vector {x}(0) are specified by:
double x[3] = { 1./sqrt(2.), 0., -1./sqrt(2.) },
while the constant vector {z} is:
double z[3] = { 1./sqrt(3.), -1./sqrt(3.), 1./sqrt(3.) }
so far i have everything done except i dont know how to account for adding the constant vector in [K] {x}(n)+ {z}, as the reader has nothing on it and i have very little experience with linear algebra [K] {x}(n)+ {z}.
can someone help me with this please? this is what i have thus far
#include <stdio.h>
#include <math.h>
void unit_norm(doubl e *vec, int cols);
void matrix_mult(dou ble a[3][3], double *b, double *c, int rows);
main()
{
int row, i, j;
double k[3][3] = {{1.2, -3.0, 1.1},
{-4.1, 6.2, -2.2},
{3.4, -2.5, -3.3}};
double y[3], x[3] = { 1./sqrt(2.), 0., -1./sqrt(2.) };
double w[3], z[3] = { 1./sqrt(3.), -1/sqrt(3.), 1./sqrt(3.) };
printf("\nIniti al vector:\n\n");
printf("x[0] = [");
for(row=0; row<3; row++)
printf(" %.6f ", x[row]);
printf("]\n\n");
for(i=0; i<=4; i++)
{
matrix_mult(k,x ,y,3);
printf("New Vector:\ny[%d] = [", i+1);
ifor(j=0; j<=2; j++)
printf(" %.6f ", y[j]);
printf("]\n");
unit_norm(y,3);
printf("Normali zed new vector:\nx[%d] = [", i+1);
for(j=0; j<=2; j++)
printf(" %.6f ", y[j]);
printf("]\n");
for(j=0; j<=2; j++)
x[j] = y[j];
printf("\n");
}
return(0);
}
void matrix_mult(dou ble a[3][3], double *b, double *c, int rows)
{
int k, s;
double dot_p;
for(s=0; s<rows; s++)
{
/* ......COMPUTATI ON.... */
/* THIS PORTION IS WHERE I AM HAVING THE PROBLEM */
}
return;
}
void unit_norm(doubl e *vec, int cols)
{
double norm;
double sum=0.;
int n;
for(n=0; n<cols; n++)
sum += vec[n] * vec[n];
sum = sqrt(sum);
for(n=0; n<cols; n++)
vec[n] = vec[n]/sum;
return;
}
Comment