Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.7K Views
|
4 Replies
|
1 Total Like
View groups...
Share
Share this post:

Plot points using the elements of a random generated matrix as coordinates?

Posted 5 years ago

Hey, So recently we got task at school. The task was to create function, which will make random matrix depends on what you entry. That was the easy part. But then we have to generate point graph. Since the matrix should have 2 and more lines, we have to take first line out of the random generated matrix and make its points as x-axis. Same goes for the second line - take its points as points of y-axis.Then connect the points and label the axes. I have bloody no idea, how am I suppost to make the points from the first two lines as point graph? This code below is what I've got so far. It works pretty well as a rangom generator for matrix.

Matrix[a_, b_] := Module[{x, y, result},
  x = a;
  y = b;
  result = 
   RandomInteger[{-100, 100}, {RandomInteger[{2, x}], 
     RandomInteger[{2, y}]}];
  Print [MatrixForm[result]]
  ]
POSTED BY: Tomáš Jahoda
4 Replies
Posted 5 years ago

Yea, I got it now. Sorry, my bad. As I told you, I'm not really good friend with using F1 with every single thing. It works perfectly. Thanks.

POSTED BY: Updating Name
Posted 5 years ago

When answering a question involving random numbers, it is a good idea to seed the random number generator with a specific value so it generates the same sequence of numbers. That way, anyone can reproduce the results. Look at the documentation for SeedRandom. Remove the call to SeedRandom to generate a different matrix every time matrix is called.

I renamed the function to matrix because all WL built-in symbols start with an uppercase letter, so it is safer to avoid using names starting with an uppercase letter to avoid potential redefinition of a built-in symbol.

The answer above does exactly what you want. With SeedRandom[1] it generates the matrix

{{38, -97, 28, -33}, {-93, -86, -34, 12}, {37, 50, -20, -99}}

And the points plotted are

{{38, -93}, {-97, -86}, {28, -34}, {-33, 12}}

Regarding joining the points and labeling, I suggest you read the documentation for ListPlot.

POSTED BY: Rohit Namjoshi
Posted 5 years ago

Hi. Thanks for the effort. I tried this but it somehow makes the same matrix over and over.

I mean, the function should print everytime different matrix even with the same entry. Then take first two lines, its points and make point graph from it.

Edit: As you can see in my function, if i type e.g. Matrix[6,6], it will generate random matrix with random lanes and columns between 2 and 6. Let's say it generated matrix which look like {{88, 22, 89},{73, 0, -93}, {-80, 8, 63}, {92, -34, -80}} - It will take firs line (88, 22, 89) and make the points as points of axis X, then it takes the secons line (73, 0, -93) and make it the axis Y. So there will be points a1[88;73], a2[22;0] and a3[89;-93]. The points should be connected and axes labeled. And everytime you press "enter" again, it will generated brand new Matrix with different graph.

I'm sorry, but I'm really not focused on this type of programming. I'm more like Visual Studio c# kid and syntax of Mathematica is kinda confusing for me, that's why I'm so lost in ploting graphs, especially in a function. :(

POSTED BY: Tomáš Jahoda
Posted 5 years ago
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard