Message Boards Message Boards

0
|
2535 Views
|
6 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Can someone write out the command below?

Anonymous User
Anonymous User
Posted 9 years ago

Some one could help me with this command it would be much appreciated. Use the Table command to enter a matrix with the integers 1 through 10 on the diagnol, 0 below the diagnol, and 1 above the diagnol

POSTED BY: Anonymous User
6 Replies
Table[Which[i == j, i, j > i, 1, True, 0], {i, 1, 4}, {j, 1, 4}] // MatrixForm

This:

Table[If[j == i, j, If[j > i, 1, 0]], {i, 1, 10}, {j, 1, 
   10}] // MatrixForm

Gives this:

enter image description here

POSTED BY: Philip Flanner
Anonymous User
Anonymous User
Posted 9 years ago

I am new to mathematica can you explain what each command after the f statement means thanks

POSTED BY: Anonymous User

Mathematica has really great documentation! Each of those commands is covered very well in the documentation along with detailed examples of usage. I am not trying to blow off your question, but that is probably the best resource for you.

POSTED BY: David Reiss
Anonymous User
Anonymous User
Posted 9 years ago

Yeah Im just trying to make sense of the commands. I know the if command takes three arguments and gives a true or false to be evaluated. So if the command j>1 is false it would result in a 0 and a 1? And i and j also go from integers 1-10 correct?

POSTED BY: Anonymous User

Yes, you are exactly right. Interestingly enough, the If statement can have a 4th argument. One can use this in the case where the test (the first argument) does not evaluate to either True or False. But if the first argument is always guaranteed to have a True or False value then the use of the 4th argument is not needed as is the case for the example here.

The lists at the end of the Table are called iterators. They have a variable and then two values that specify where the variable starts and where it ends when the increment is 1. There is another version with 4 items in the list where the 4th item is the increment when one wants it to be something other than 1.

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract