Sign in to follow this  
Roberts91

Exercise 5 - Matrix Addition

Recommended Posts

Hello everyone again! I was wondering if you guys could help me again I'm on a new exercise called Matrix Addition. And all the author gave me is what you can find below in my link. All you have to do is copy and paste and it send you directly to the magnified image of my exercise. I'm actually kinda confused on how to do it. I tried making arrays and then referencing back to them to do an addition on each of them. It became a mess of code. And it probably wouldn't have even worked right. So I was wondering if you guys could help me on what I need to do to make this program work. Thanks! Link to picture of exercise: http://i32.tinypic.com/wb5kpt.jpg

Share this post


Link to post
Share on other sites
0) What don't you understand? Do you know, for example, what a Matrix actually *is*?

1) What have you figured out so far?

Do you have a structure that represents a Matrix? You don't seem to be expected here to read in any data; you just set up two hard coded Matrix objects and add them.

We're not psychic. If you tried something and want to know what's wrong, you should show what you tried.

2) You can link images here with ordinary HTML <img> tags (use the thumbnails from the image hosting site, not the full sized image, unless it's small). Although honestly, it would have been less effort to just type out the text from the book than it was to scan the page, put it up on an image hosting site and then explain how to find it.

Share this post


Link to post
Share on other sites
0) Yes I do a matrix is an array of an array. A multidimensional array both the same thing. So let's say with the picture provided it wanted us to use these numbers and add them accordingly. -5, 2, 8, 1, 0, 0 = A / 1, 0, 2, 0, 3, -6 = B

So we say... umm.. hmm.. okay

int a[2][3] =
{
{-5, 2, 8},
{1, 0, 0}
};

And then for B:

int b[2][3] = // which will be same thing for a
{
{1, 0, 2},
{0, 3, -6}
};

1) Well let's see I figure that I will need a multidimensional array aka matrix and that I will need to take a + b = c.

I guess where I'm confused at is that I don't know the syntax for adding a + b to = c because if you do c = a + b; your gonna get errors for trying to add pointers.

2) Actually when I posted my other exercises I tried typing out there examples just like the book said and it was too big of a task when I can simply take a picture of it, crop it, and host it, so everyone can see it just like in the books. And when I tried to use the HTML tags I tried using [img] *image here* [/img]. I didn't know about the <img> tag.. Sorry!




Share this post


Link to post
Share on other sites
I don't think you are quite familiar with the concept of a matrix, at least in the mathematical context, which is the one relevant here. A matrix is a multi-dimensional array, which represents some abstract quantity (for example, a transformation – a single matrix might represent the idea of rotating an object 45 degrees around an axis and then translating it by 3 units along that axis in a certain direction) and has specific operations defined upon it. Matrices and their operations are not built in to C++ – you have to define them yourself (or, better yet, use an existing library).

The Wikipedia article should help. If this is a pedagogical programming exercise, rather than a linear algebra one, you're probably most interested in the "Adding and multiplying matrices" section (although a scan of the rest of the page will almost certainly be helpful).

Share this post


Link to post
Share on other sites
Quote:
Original post by crazysk8er
I hope that I understood what you were wanting, and that this helped.
edit: explained some code


This problem looks like homework, which is why people weren't just giving the answer.

;-)

Share this post


Link to post
Share on other sites
Quote:
Original post by Roberts91

1) Well let's see I figure that I will need a multidimensional array aka matrix and that I will need to take a + b = c.

I guess where I'm confused at is that I don't know the syntax for adding a + b to = c because if you do c = a + b; your gonna get errors for trying to add pointers.

Well, if you read your exercise closely, it tells you what to do.

"Using a double for-loop to iterate over the matrix elements, compute the sum of each component and store the result in the third matrix (e.g., C[i][j] = A[i][j] + B[i][j] )."

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this