Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Java Homework

Name: Anonymous 2009-10-27 18:58

They want me to multiply a matrix using arrays..
So the matrix is an array of arrays?
I'm a bit confused..

if i say
double[][] matrix;
how do i tell which [] has the rows and which has the columns? or is that for me to define?

Name: Anonymous 2009-10-27 19:07

homework
Back to /g/, please.

Name: Anonymous 2009-10-27 19:09

Name: Anonymous 2009-10-27 21:34

>>1
Yes, you decide. There are various conventions, see row-major vs. column-major.

Name: Anonymous 2009-10-27 21:39

double[arrays of doubles][doubles] matrix;
but it doesn't really matter which way you do it anyways (except for possible performance losses caused by paging).

Name: C Master 2009-10-27 22:30

>>1
how do i tell which [] has the rows and which has the columns?

In a real language:
1) Clear the array if necessary
2) Poke [0][1] of the array with a value
3) Look at the address of [0][0] +1 (or plus however many bytes wide a single element is)
4) Is it still clear or is it the value you put in [0][1] ???

Your language may not even allow you to do something like this but I know it would work in say, C, or most any language that lets you use pointers in any way.


#include <stdint.h>
#include <stdio.h>
#include <string.h>


int main()
{
        uint8_t myArray[2][2];

        memset(myArray, 0, 2*2);  /* set all elements to 0 */

        *(&myArray[0][0] +1) = 1;


        if (myArray[0][1])
                printf("Row-major order");
        else
                printf("Column-major order");
}


The result in C is that the second dimension is that [0][1] = 1, indicating that you begin counting with the second dimension.

I have no idea if you can do anything like this in Java.  As far as I know, pointers are forbidden or something like that.

Name: Anonymous 2009-10-27 23:27

you look like you need a hand from someone who isn't a progtard.

I think you're referring to the mathematical matrix construct?
let's say you had these two:
| 9 8 7 |
| 6 5 4 |
so, if you've got a matrix that's 2 rows of three, you can still handle it in Java with one primitive construct; it's called a multidimensional array (or, an array of arrays). if double[] is an array of doubles, then know now that double[][] is an array of double arrays.
from my example:
double[][] matrixA =
{{9,8,7},
 {6,5,4}};
still two rows, still three columns per row; only now we call them one array of two double-type arrays.
you can call values the same way you did for single-dimension arrays. look back at matrixA; the formatting I used is legal in the compiler and might help you to organize your thoughts. for matrixA[i][j], i= the index of the single-dimension array you want to call, and j= the index of the element in that array.
think of it this way: if you have a single-dimension array, you would call the fifth element by array[5]. I haven't told you what type this array is; suppose its type is, in fact, also array. array[5] will return another array, and you call this new array's elements with the same syntax appended to the original call: the 2nd element in the fifth array is array[4][1]. and that syntax expands forever: there is no limit to the number of array dimensions other than your own processor speed.

So, doing your homework for you now, using the example above.
as someone learning, you might benefit from defining a Matrix object class, but I suspect you haven't been introduced to multiple-class structuring, and I think it would be a lot of hassle. so we'll define a matrix as a double[][] (a double-type two-dimensional array). we'll use the one I made up at the top of this post.
I imagine you have exposure to some loops by now; to multiply a whole matrix by a scalar, you multiply every element by the scalar. an idiom to loop through every element in a 2d array is
public static double[][] multiplyMatrixByScalar(double[][] arr, double scalar){
for(int i=0; i<arr.length; i++) //for every index in the top array object
{ for(int j=0; j<arr[i].length; j++) //for every valid index j in the ith array
 { arr[i][j] *= scalar;} //multiply the jth element of the ith array by scalar.
}
}

now you tell me if that helped.

Name: Anonymous 2009-10-27 23:28

>>7
Edit: almost on the top damn line, that's one matrix, not two. sorry.

Name: Anonymous 2009-10-27 23:34

>>7
also edit: the fifth element is array[4].
also edit: add the return statement to multiplyMatrixByScalar. or make it return type void in the method declaration.

damn my inability to proofread. I also haven't slept in a few days.

Name: Anonymous 2009-10-27 23:35


  double A[10][10], B[10][10], AtimesB[10][10];

  for (i=0; i<10; i++)
  {
     for (j=0; j<10; j++)
         {
        for (k=0; k<10; k++)
                {
             AtimesB[i][j] += A[i][k] * B[k][j];
        }
     }
  }


For my help, all I request is that you write sage in the Email field of all future posts.

Thanks!

Name: Anonymous 2009-10-27 23:39

>>10
You'll be lucky, and more to the point why did you help him?

Name: Anonymous 2009-10-27 23:49

>>7
I figured it out and submitted my own version already before seeing your reply, but thanks anyway, I will look at this later to enforce my understanding of matrices and and multi dimensional arrays even though the assignment is over..

Name: Anonymous 2009-10-28 1:27

>>11
Notice it's O(N3)?

Name: Anonymous 2009-10-28 1:50

>>13
Why are comp sci 101 students still flooding /prog/?

IHBT

Name: Anonymous 2009-10-28 1:54

>>13
I did, but my point still stands.
>>14
Happened about the same time last year too

Name: Anonymous 2009-10-28 2:12

>>15
It's the period after midterms where they have time to dick around because tests are over and a bit of ego because they got decent grades on easy tests.

Name: Anonymous 2009-10-28 2:26

>>16
OVERANALYSIS ALERT

Name: Anonymous 2009-10-28 2:34

You guys think you're more intelligent because you have been coding since you were children..

Name: Anonymous 2009-10-28 2:35

You guys think you're more intelligent because you are

Name: Anonymous 2009-10-28 2:46

>>18
I'm still a child

Name: Anonymous 2009-10-28 3:24

>>18
If you were intelligent, you would have been coding since you were a child.

Name: Anonymous 2009-10-28 3:44

OH MY GOD CUM IS FLYING EVERYWHERE OHHHHHHH

Name: Anonymous 2009-10-28 12:03

I'm 12 and I just finished my ANSI C compiler.

Name: Anonymous 2009-10-28 12:04

¡This cheese is burning me!

Name: Anonymous 2009-10-28 12:32

I'm 13 and I just finished my ISO C compiler in ANSI C.

Name: Anonymous 2009-10-28 12:35

I'm 14 and I just finished my C99 compiler in ISO C.

Name: Anonymous 2009-10-28 12:39

I'm 78 and my name is Larry Wall and i just finished Parrot.

Name: Anonymous 2009-10-28 12:42

I'm 19 and I just started my Scheme debugger in Scheme

Name: Anonymous 2009-10-28 12:49

I'm 18 and I'm in the middle of writing C99 compiler in Common Lisp.

Name: Anonymous 2009-10-28 12:50

my name is Jim, im 21 and i'm an anonymous alcoholic.

Name: Anonymous 2009-10-28 12:52

>>30
Go away Jim, we don't want no religious types round theseaways

Name: Anonymous 2009-10-28 15:14

My name is 9000 and I'm writing a multi-domain interpreted language that will support every language ever inline.

eg:


c {
  include <stdio.h>
}

java {
  String s = "hello world";
  EXPORT_STRING(s);
}

c {
  IMPORT_STRING(&s);
  printf("%s\n",s);
}

ruby {
  IMPORT_STRING(s)
  puts s
}

Name: Anonymous 2009-10-28 17:16

My name is Buck and I'm here to fuck

Name: Anonymous 2009-10-28 17:19

>>6
Please do not confuse the Java programmer with a real language

Name: Anonymous 2009-10-28 17:33

My name is Arty and I'm here to Party

Name: Anonymous 2009-10-28 17:43

>>32
Already been done.

Name: Anonymous 2009-10-28 18:17

My name is Hurr and I'm here to Durr

Name: dich snake 2009-10-28 18:29

                       _.-------.                   
     ----------------''       ,-.`-----.               
                             ( X )      `-.            
                              `-'  ,---.   |           
                                  .     `---       ,----
    -----------------------.       `-.            .    
                            `---------`   ,--+-----`----
                                         ;    :        
                       Can I suck your   +----;        
                       dich today?        `--+----,----
                                                 (     
                                                  `-----

Name: Anonymous 2009-10-28 20:25

>>36
This isn't Wikipedia.  On /prog/ we provide links.

Name: Anonymous 2009-10-28 20:39

Name: Anonymous 2009-10-28 22:26

Name: Anonymous 2009-10-28 22:40

>>41
Katahdin is a programming language where the syntax and semantics are mutable at runtime.
(☞゚ ∀゚ )☞
☜(゚ ∀゚ ☜)
☝(゚ ∀゚)☝
☝(゚∀゚ )☞

Name: Anonymous 2009-10-29 0:06

>>41
As soon as I read that it has anything to do with .NET I realized that it was a retarded idea.

Also the example looks like C++.

Name: Anonymous 2009-10-29 1:35

>>43
Right, because one implementation defines everything about it.

Name: Anonymous 2010-11-28 11:08

Name: 2013-01-25 18:15

猱㊐鉁⥇怙昘順肗ၦむ鞘ㅙগ礱傘էކ㒇̗㕷蕷आ鍔研刀虰㑸摆艱舱㙗唅☡㈡㦉䕐䑴ᘹ㘘┅怅鄧儢ॱ薕暘香᝷䌦東䆒␦ކ餇蒙昴锂送鑂㔆ٵ瘧⠂聢ኗ慑襦卒猅聅慂砡鉱ኆ钕䀧䀩捑獢灓楣瘉敃晖恸戔࠵撁蝢镱焰琥灃蝷斖㉑ⅱ鑵昩䒃衹鍔園鐖ᑖ䑘䁱奣បᜃ՘梑蘠圇捦脀④✐喗╶ࡣ㈅ᚖᅱⅢ鍱㞁猁摹ᦕ蕈阐膆♶艖墈⁆兂夷ᜒ祕脳㐰蔐ᤗ⑦ȶ㐱㠕ၱհц瘈䈰‚᥸❣⎆琩墐蕥㢐搕枈ႉ㐶䉆蘄砲锉ݓ∁ቈᖈ♲⅖犗᜔吆ቷ愘閗硆䉁ᑶ蠠❐ᑕ頥夳ታ唹熘荳ե犆栅呉ኗᄹ瑸ㅶ虶瘕脧жѰɐ眤蔶荴ޖ楓晘扴ж楹舡ၣ覕咆鑨猨▗聕ᄨ錢䜶顰䁘᝗塩ᔳ脱⎘〗Ԡɵᤗ吂荵瘴桥吠ᤈ䥡ᘔ抗猶杵鉣偹椦葥杨ᝐ改錓枆䉃ᆈ褂刈†喉ɲ慒ᤴȑᡃ䜔ࠤࡆᒕ䠤ȣ甩␣㜓椅❤块堒ؘІᔰ抐蝩偩%蜖∱码牀奶匂鍱☥夹鐑呇頢醅ᐉ՗舗ঙけ‑敷猇碇馑敆摙䑒锥㕉夰芒鉐場祆␑鞗猹䌘顈㔡焕艵刱㄄斐㑰䜒䘧す砀塓㠥ȕ腸ᄹ銒՘䘷掄硄瑩犕⥐肗斒<㤣㦕捃甘煣ࢂ䂗灧ݠ础ᤘ㌇煇膙眣☩銑餂閖㙁ᤅ㒃舀醕鍳Ⅴ挆瘔熖昖玃煦剒᜗㕕耉厅㢄酇㠰ᡲـ唹⍘頱杖ᥢ阠ᔸ獈㑉斅由䠸ťᖓݲ⍔朐睗瀄ᘵ噑瘁⁃I䘶噐碙茷襧⡣腢▄面啒زつ酡坉茩悉ᝉ鉹邆錩㞁㡱ᔩ⌷㦆蕓∦嘢聕琶瘕⁷塴㡔桢⡉䉱ᢈࡔ⥗匱ᤄ㦐逶䑧ᙴܵ块̂扢嘳ℙ蚈衸ᄈ掄ᘖƄ攑䜰啃斖⎙牓梖≖㠈䐠唁Ƅ唃㥘候⁳脴襴恩䄧⠥

Don't change these.
Name: Email:
Entire Thread Thread List