473,413 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Need Help With This Vector Topic. Fast

NEED TO MAKE A PROGRAM which computes the current value of the vectors {x}
based on the following forward iterations:

this >>> {x}(n+1) = [K] {x}(n), n = 0,1,2, ... ,8,9.

In other words, the next vector {x} is equal to the product of [K] and
the current vector {x}.

Perform the matrix multiplication by using the function:

void matrix_mult(double a[4][4], double b[4], double c[4], int rows);

You should pass the matrix [K] and a pointer array {x} to matrix_mult()
which will pass back a new vector {y} ).

[K] is a constant 4x4 matrix defined by:

double K[4][4] = { { 2., -4., 1., 0.},
{-4., 5., -2., 1.},
{ 1., -2., 6., -3.},
{ 0., 1., -3., 7.}};

The initial components of the vector {x}(0) are specified by:

double x[4] = { 1./3., 2./3., 1./3., pow(3.,0.5)/3.};

First, print the value of the initial vector {x}(0) on the screen.
Then, perform forward iteration 10 times (for n=0 to 9). Each time
after new vector is computed from [K]{x}, normalize that vector by
using the function

double unit_vec(double vec[4], int cols)

which was discusseed in class (see Program w8-5.c; this function
transforms a vector to a unit vector - of magnitude 1). For the
matrix multiplication with the vector [K]{x}, see Program w8-3.c .

Always use the normalized vector as the vector {x}(n) for the next
iteration.

For each iteration, print the new vector, its length, and the normalized
new vector in main().

I BUILDED THE SKELTON BUT I AM NOT SURE.

PLEASE CAN SOME EXPERT IN THIS FIELD HELP ME THIS.
I WILL REALLY APPRICIATE IT
THANK YOU.

#include <stdio.h>
#include <math.h>
double unit_norm(double vec[4], int cols);
void matrix_mult(double a[4][4], double b[4], double c[4], int rows);
main()
{
double K[4][4] = { { 2., -4., 1., 0.},
{-4., 5., -2., 1.},
{ 1., -2., 6., -3.},
{ 0., 1., -3., 7.}};
double y[4], x[4] = { 1./3., 2./3., 1./3., pow(3.,0.5)/3.};

// Enter your C statements
.........................
.........................
}

void matrix_mult(double a[4][4], double b[4], double c[4], int rows)
{
// compute c[]=a[][]*b[]
..........................
..........................
return;
}

double unit_norm(double vec[4], int cols)
{
double sum;
// normalize a vector
...........................
...........................
return sum;
}



OUTPUT LOOKS LIKE THIS

Initial vector:
x[0] = [ 0.333333 0.666667 0.333333 0.577350]

New vector:
y[1] = [-1.666667 1.910684 -0.732051 3.708119]
The length of this vector is: 4.551322
Normalized new vector:
x[1] = [-0.366194 0.419808 -0.160844 0.814734]

.
.
.

New vector:
y[10] = [-3.096892 5.315900 -6.556405 6.293838]
The length of this vector is: 10.974897
Normalized new vector:
x[10] = [-0.282180 0.484369 -0.597400 0.573476]

*/
Nov 20 '06 #1
1 1779
It Is Due In 24 Hours Please Somebody Help Me.
Nov 20 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: JustSomeGuy | last post by:
I have a routine that evaluates a polynomial equation that have 3 variables x,y,z of orders 1,2,3 the coefficients of the polynomial are in an array. This routine is quite slow and I'd like to...
66
by: Mike Stenzler | last post by:
I am new to Template programming and I would like to create an array of user-defined class objects using MFC CArray. Normally I would use linked list processing - create an object class and then an...
11
by: Steven T. Hatton | last post by:
The reason Stroustrup warns against using set and get functions is that an object of class type should be designed in such a way as to maintain some invariant. All operations on the class should...
15
by: drdoubt | last post by:
using namespace std In my C++ program, even after applying , I need to use the std namespace with the scope resolution operator, like, std::cout, std::vector. This I found a little bit...
6
by: isaacyho | last post by:
Is there a fast way to crop a vector? I have a vector of size n, and want to reduce it to some subregion (x,y ). Seems like you shouldn't have to recopy all of those elements into a new vector,...
0
by: rokuingh | last post by:
ok, so i've been working on this one for quite a while, and the code is very big so i'm just going to give the relevant parts. this is a program that builds polymers (chemical structures of repeated...
8
by: markww | last post by:
Hi, If I have a vector of structs like this: struct IMAGE { unsigned char *pPix; string strName; int nNumber; };
13
by: Gernot Frisch | last post by:
Which method is the fastest/best: std::vector<intfoo1() { std::vector<intv; ... reutun v; } std::vector<int>& foo2()
82
by: Peter Olcott | last post by:
I need std::vector like capability for several custom classes. I already discussed this extensively in the thread named ArrayList without Boxing and Unboxing. The solution was to simply create...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.