how to read library documentation-Math.NET ?

PJ33

Member
Joined
Jul 23, 2021
Messages
7
Programming Experience
1-3
Hello I am new in C# and I try to understand on how to read the documentation of libraries and implement it.
Here an example from is shown:
using System; using MathNet.Numerics; using MathNet.Numerics.LinearAlgebra; class Program { static void Main(string[] args) { // Evaluate a special function Console.WriteLine(SpecialFunctions.Erf(0.5)); // Solve a random linear equation system with 500 unknowns var m = Matrix<double>.Build.Random(500, 500); var v = Vector<double>.Build.Random(500); var y = m.Solve(v); Console.WriteLine(y); } }

I tried to understand how this is related to the documentation found here: MatrixBuilder<T> - Math.NET Numerics Documentation

What I understand is that I need to import the general library MathNet.Numerics and then the specific part of the library which is of interest, MathNet.Numerics.LinearAlgebra.
I am not sure why new wasn't used when the new Matrix object is created though.
My last question is why we use Build before of random.
I would expect to use this command:
var m = new Matrix<double>.Random(500,500)
Also, in the documentation there is everywhere this: Matrix<T>
As far as I understand T correspond to the type of the matrix thus we use double, but how is this called (<T>) and are there any more of this that is good to know to be able to use documentation?

Thank you in advance.
 
You couldn't do this:
C#:
var m = new Matrix<double>.Random(500,500);
because Random is not a member of the Matrix<T> class. the Build field returns a MatrixBuilder<T> object and that it is what you call the Random method on to build a random matrix.

The <T> part indicates a generic class. The most commonly used generic type is List<T>. Basically, a generic class defines a set of classes, rather than just one class. You get to specify what type T is in your code to set any of the generic behaviour of that object. For instance, a List<T> will only accept an object of type T when you call Add, so a List<string> will only let you add a string and a List<int> will only let you add an int. Similarly, a Matrix<string> can only contain string objects and a Matrix<int> can only contain int values.
 
You couldn't do this:
C#:
var m = new Matrix<double>.Random(500,500);
because Random is not a member of the Matrix<T> class. the Build field returns a MatrixBuilder<T> object and that it is what you call the Random method on to build a random matrix.

The <T> part indicates a generic class. The most commonly used generic type is List<T>. Basically, a generic class defines a set of classes, rather than just one class. You get to specify what type T is in your code to set any of the generic behaviour of that object. For instance, a List<T> will only accept an object of type T when you call Add, so a List<string> will only let you add a string and a List<int> will only let you add an int. Similarly, a Matrix<string> can only contain string objects and a Matrix<int> can only contain int values.
I see what Build is for, but how can I interpreat it from the documentation? If I am not mistaken is not mentioned anywhere
 
I've never used Math.NET but it took me a couple of minutes to find the information to answer your previous question and a couple more minutes to find this:

 
I've never used Math.NET but it took me a couple of minutes to find the information to answer your previous question and a couple more minutes to find this:

I found this as well, I sort of know how to use it but I am trying to learn how to use a different library and I have this as a reference for the documentation that's why I need to understand where the Build comes from, I dont want to rely on others' projects
 
I found this as well
So you lied when you said that it's not mentioned anywhere? Gee, that really makes me want to help. I feel like this is a waste of time. The documentation says what it says. It's not really for us to teach you how to read documentation. The Build field returns an object that can be used to build a Matrix. What's not to understand? If what you're actually asking is why they used a separate class for the building instead of including it in the Matrix class itself, you ought to read up about the Single Responsibility Principle. If that's not what you're asking, I have no idea what you're asking or why.
 
What I meant is that, from the documentation itself and not fromthe examples, I couldnt see why I need to use Build.
I have both attached an example tha shows the format as well as the website so I thought it was clear enough that I am trying to figure out everything from the documentation and not the example.
So what you say is that the only way to answer my question is from the exampls or the SRP, I am not missing anything from the documentation itself, right?
 
A programming reference is not a tutorial. It tells you the what and often in a very bare-bones format. A very comprehensive reference may also tell you some of the how and why but that is far more the domain of tutorials. That Math.NET documentation is very terse and sparse, so don't expect any great explanations there. It tells you what types and members are available and the very basics of what they do. How to use them is something else.
 
Back
Top Bottom