0
$\begingroup$

This question already has an answer here:

I am new to Mathematica and I am very impressed with its features. Although I don't understand how to do a simple thing: for example, I want to create few point variables (say a,b,c,d,e), each storing its x and y coordinates. In Java, I would write something like this:

class Point {
    float x;
    float y;

}
...
Point a;
a.x = 2,5;
a.y = 1,2;

How do I do same thing in Mathematica? Thank you!

$\endgroup$

marked as duplicate by rhermans, m_goldberg, MarcoB, b3m2a1, Szabolcs Sep 17 '17 at 18:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    $\begingroup$ Just define n-dimensional points/vectors as length n lists; e.g. a = {2.5, 1.2}. $\endgroup$ – J. M. is away Sep 17 '17 at 11:00
  • $\begingroup$ @J.M. How do I access elements? $\endgroup$ – CreFroD Sep 17 '17 at 11:02
  • 2
    $\begingroup$ Mathematica is not object-oriented. I suggest you go through a few tutorials and see how things are usually done the Mathematica way. What you know from Java or C should not be your starting point when learning Mathematica. $\endgroup$ – Szabolcs Sep 17 '17 at 11:02
  • $\begingroup$ Look up Part[] and Extract[] in the documentation. Try e.g. a[[1]] . $\endgroup$ – J. M. is away Sep 17 '17 at 11:03
  • 3
    $\begingroup$ "How do I access elements?" By reading the documentation. A minimal level of Mathematica knowledge is expected before you ask questions here. I am not being snarky. JM's answer is technically accurate, but you would not usually work this way with a 2D vector most of the time. $\endgroup$ – Szabolcs Sep 17 '17 at 11:03