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

Pages: 1-

My homework

Name: Anonymous 2006-11-25 12:22

i'm desperate, i have no clue how to programm
if anyone can make my homework i'd largely appreciate it cuz i have to deliver it a few hours

It's to be done in Mathematica, which i've been told is a lot like C

"Using only the list functions First, Last, Rest, Append, Prepend, Length, {}, [[.]] and [[.,.]], define in Mathematica an 'f' function that receives as an argument a square matrix of natural numbers (including 0), and goes through it using two boxed (one inside the other) While cycles and returns the list of lines where the minimum of the matrix occurs (without repetitions)."

Name: Anonymous 2006-11-25 12:23

lol wut

Name: Anonymous 2006-11-25 12:35

>>1
Mathematica is nothing like C. I can't help you.

Name: Anonymous 2006-11-25 13:03

>>3
If anything, you were the only person on the entire internet willing to. Too bad you're anonymous ;D

Name: Anonymous 2006-11-25 13:29

boxed (one inside the other) While cycles

boxed lol

Name: Anonymous 2006-11-25 17:44

>>1

Ok, to define a function f that takes a single parameter (your matrix, notated by 'm'), you need to do it like so, putting the content of your function in between the brackets:

f[m_] := (

)

Multiple instrucions you put in your function need to be separated by semicolons.

A matrix is defined as a list of lists. A list is notated as curly brackets with its elements separated by commas. So, for example, here is a matrix and its corresponding list definition:

matrix m

/     \
| 1 2 | 
| 3 4 |
\     /

in mathematica,

m = { {1, 2}, {3, 4} }

This is the purpose of the {} function mentioned in your question. The [[.]] and [[.,.]] functions operate on the matrix - the former returning a row and the latter an individual element.

Example, using the previous matrix:

m[[1]] asks for row 1, which is {1, 2}
m[[2,1]] asks for the 1st element of row 2, which is 3

The First and Last functions are straightforward too, getting the first and last elements of a list. So if you had a list L = {1, 2, 8, 4} then First[L] is 1 and Last[L] is 4.

Rest[L] is interesting in that it deletes the first element of the list and just gives you the rest of it - the previous list would be {2, 8, 4} when this function is applied. You can use this to help you iterate through the elements of a list.

Prepend and Append functions add an element to the start and end of the list respectively. So using the list L above,

Prepend[L, 5] gives you {5, 1, 2, 8, 4}
Append[L, 5] gives you {1, 2, 8, 4, 5}

The Length function just gives you the length of a list. In your case, this will be useful for checking for an empty list (i.e. Length returns 0)

Finally, the While function is what will tie all this together. It's not hard to use when you get your head round it. Basically what it does is evaluates the first parameter - if that is true then it evaluates the second. It repeats this until the first parameter evaluates to false.

Here's an example:

L = {1, 2, 8, 4}
While[
  Length[L] > 0,
  Print[L[1]];
  L = Rest[L]
]

This prints out all the elements in the list L.

Hope all this explanation helps you with your homework. Good luck, Anonymous!

Name: Anonymous 2006-11-25 18:49

>>6
That was completely awesome! I'm not the OP but you sir have earnt my respect for doing so much to help the OP. From now on, I'll respect Anonymous.

Name: Anonymous 2006-11-25 19:22

I hope it's enough for him to figure out what to do. He sounded pretty desperate.

Name: Anonymous 2006-11-26 9:33

>>8

No shit?

>>1 i'm desperate,

Name: Anonymous 2006-11-26 9:34

>>9

Did you get it sorted then?

Name: Anonymous 2006-11-26 11:34

WTF UGUYS THIS IS URGENT HELP ME NOW!!!!!!!!!!!!!!!!!!!!1

Name: Anonymous 2006-11-26 12:56

>>11
So you have to do it for monday.

Listen, >>6 the awesome Anonymous did more than 99% of us would do for you. If you can't do the rest yourself, and sorry to be this harsh, you deserve to fail.

Name: Anonymous 2006-11-26 13:28

Do you understand what the "minimum" of a matrix is (I don't)? How to get it without the restrictions?

If you know those, just work from there.

Name: Anonymous 2006-11-26 13:39

>>13

It's the smallest value in the matrix.

For example, if the matrix is

 1 -4 5
 -4 -2 0
 -2 1 5

then the minimum is -4.

Name: Anonymous 2006-11-26 17:03

>>12
WTF STOP FLAMIN U FAG ALL I ASKED WAS SOME URGENT HELP NOW GTfO!!!!!

Name: Anonymous 2006-11-26 18:05

>>15

TROOL

Name: Anonymous 2006-11-26 18:26

>>1
hey guys, i managed to get it done by a classmate within the deadline so i'm kinda glad about that.
If anyone is wondering, this was the answer that was accepted:

f = Function[n,
      Module[{i, j, k, res},
        i = 1;
        res = {};
        l = Length[n];
        minimo = Infinity;
        If[l >= 1,
          While[i ≤ l,
              j = 1;
              k = 0;
              While[j ≤ l,
                     If[n[[i, j]] <
         minimo, (minimo = n[[i, j]]; res = {};
          res = Append[res, i]; k = i; ), If[n[[i, j]] == minimo, If[
              k ≠  i, res = Append[res, i]; k = i;, k = i]]];
                j = j + 1;
                ];
              i = i + 1;
              ];];
        res
        ]
      ];


I'll just have to get over my problem which is bleeding syntax errors. I just...can't...do it...dammit!!

Name: Anonymous 2006-11-26 19:10

Mathematica kinda fails... Here's the same done in Python:

min(min(x) for x in a)

Name: Anonymous 2006-11-26 22:31

>>18

Way to go for totally misunderstanding the problem.

Name: Anonymous 2006-11-27 3:42

>>19
I did what >>14 said :(

Name: Anonymous 2006-11-27 4:33

>>20

Read the actual question in >>1

Name: Anonymous 2006-11-27 10:57

yeah guys, it's the thread maker again, guess what, if i can't do a problem in mathematica on a test this one won't count.

Name: Anonymous 2006-11-27 12:25

>>22

You'd better start learning something then you lazy fuck

Name: Anonymous 2006-11-27 16:28

>>23
nah, i'm good i'm gonna go sleep

Name: Anonymous 2006-11-29 5:54

This thread is made of failing students

Name: Anonymous 2006-11-29 10:36

>>22

Faggot. Also, dicks. i herd u liek dem.

Name: Anonymous 2006-11-29 12:30

>>26

stfu, ur the pooper trooper

Name: Anonymous 2006-11-29 21:50

>>22
Then you're stuffed. The only way to gain proficiency in programming is to practice. No shortcuts, no special hints or tricks.

Name: Anonymous 2009-01-14 14:14

lol

Name: Anonymous 2009-03-06 5:56

or is inverse not.

Name: Anonymous 2010-11-26 3:15

Name: Anonymous 2011-02-02 22:59

Name: Sgt.Kabuﵻ滾kiman❹ 2012-05-28 21:10

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

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