Click to See Complete Forum and Search --> : Help in C!?!?


Grega
04-23-2003, 06:52 AM
Hi everyone.
I have a problem in programing we have to do for homework. I wrote something but it doesn't quite work so if anyone could help me with the code for program i would be very thankfull:confused:

We have to do this:
A+A where A is the matrix of nxn and we have to do this for n times (A+A+A+A+A <-- IF n=5) and where sum of C=min(A+B) hope u'll know what i mean coz its hard to write it?!
:confused:

I attached file sem2.txt where i wrote some code!

Thx in advance :)

bwkaz
04-23-2003, 09:19 AM
We will not do your homework for you. If you are having trouble with a certain section of the code, then we'd be happy to help with that (but again, we probably shouldn't provide answers directly), and other similar specific questions will probably be answered, but "do my homework for me please" is not acceptable.

Look at it this way: your teacher/professor/whoever may very well read these boards.

That said, you will want to include more of the problem you're having -- does your code not compile? Or does it just not run right? What is the matrix C supposed to be? What about B?

Grega
04-23-2003, 09:55 AM
I didnt ask for u to do my homework i did te whole concept and i know how to do it i just have problem with syntaxis... i dont understand the whole pointer think... if u check the file i attached the whole think is written i just asked if someone could tell me why that damn think doesnt work as it was suposed to...
i wouldn't do someones homework either...

the thing compiles
B is A actualy A+A+A+A+....+A for n times as a dimension of the matrix..

bwkaz
04-23-2003, 01:16 PM
Well... the code as written makes very little sense to me as well. A large part of this is the choice of merely single- or double-letter variable names -- what the heck are u, v, r, t, st, x1, x, and v1 supposed to mean? Perhaps if you named them something a little more descriptive of their function, that would help you (and me, as well) understand what they're doing.

Are you getting errors when compiling it? If so, what are you typing to do that compile?

So let me get this straight -- A is an nxn matrix, and B is A+A+A+...+A (n times). Basically, B is n*A (that might help with some of the issues, maybe).

So then where does C come in? "sum of C" doesn't make any sense, really -- do you mean the sum of the elements in C, or something else? "=min(A+B)" also doesn't really make any sense -- there's no "minimum" of only one thing (A+B). The "minimum" function also isn't defined on matrices.

Grega
04-23-2003, 01:43 PM
OK first thanks for trying I know its written very confused so i'll try to be more specific:
,which is not that easy cos i am not very good at english and dont know expresions in math that well:
A is an nxn matrix
the program should do A+A like these example for n=2
This is A
4 2
2 3

4 2 * 4 2 = 8 6
2 3 * 2 3 = 6 4

this * operation should work like that in program
(though i dont think that part is a problem)
the whole matrix should be written in a file in one line without spaces 100000011110..... and so on, for n=2 should be there 16 numbers 2x2x4 4 byte for each integer!

coz we dont know what size matrix will be i had to use malloc, hope i used it right?!

those u,v,r,t,... are just variables for algorithm to work;
i think the problem why think istn working is in pointers and the way i used them but i was working with pointers for first time i dont know if they are used right?

Hope this helps some

Thx

bwkaz
04-23-2003, 06:25 PM
The calls to malloc all look just fine. So do most of the pointer references...

Unfortunately, I can't really see what's going on in that example, as far as the multiplication (is it that? Or is it addition?) goes.

Matrix addition would look like:

4 2 + 4 2 = 8 4
2 3 + 2 3 = 4 6

In other words, you add each component individually. Multiplication is:

4 2 * 4 2 = 20 14
2 3 * 2 3 = 14 13

Each component is the dot product of the corresponding row and column of the two matrices, respectively -- the element in the first row and second column of the result is the dot product of the first row of the first matrix with the second column of the second matrix. (4 2) * (2 3) = 4*2 + 2*3 (multiply the first coordinates, multiply the second coordinates, then add the two together) = 8 + 6 = 14.

But what you're doing in the example is neither of these...

Grega
04-24-2003, 01:29 PM
Done it :)))
thanks for trying to help but after long night and "few" coffies i did it!
the whole problem was in pointers that i was using :(.
but anyway nw it works
Thanks
Have a nice day
Grega

bwkaz
04-24-2003, 01:52 PM
Umm. OK, glad to ... err, help. ;)

Can you say what it was with the pointers? Or is it too complicated?