Highlight text to annotate itX
I'm Trevor Misfeldt and welcome to our tutorials on using NMath software.
This video will show you how to get started with NMath. Please install our thirty day fully- functional evaluation version.
The first task is to create a new project.
We are going to make a simple console application.
Just for our first demonstration.
We already have NMath installed,
so we can go and add a reference to NMath so I'll do that now.
Select "Add reference...", bring up the Reference Manager
and then scroll down to see the various NMath assemblies.
So in this simple example,
the only assembly I need is NMath so I'll select that.
Now that I have NMath referenced, I need to add some "using" statements.
Do "using CenterSpace.NMath"...
and then you can see there's "Core", "Matrix" and "Analysis". I'm going to need "Core" for my main data structures.
I'm also going to need "Matrix" to do an LU factorization.
I need to go up to my Configuration Manager and just show you something quickly.
"Any CPU" comes up and that's what we want.
Because NMath will take care of 32 and 64 bit so please select "Any CPU".
Now I'll go to my project properties now of a project properties. In .NET 4.5 one of the build options is "Prefer 32-bit".
Please deselect that. We don't need that. NMath will take care of 32 bit and 64 bit if that is off.
Now we are ready to write some NMath code.
So, the first thing I'll do here is to create
a random number generator so we have a whole host of different random number generators
I'm going to choose a uniform random number generator
to create, say, numbers between one and ten
and I'll pass in a seed.
Now, I'm going to create a new DoubleMatrix. So, this is one of our main data structures. It's a 2-d representation of numerical data.
I'll make a small 3x3 matrix and fill it with the random numbers from our random number generator.
Now, I'm going to go to our Matrix namespace and create an LU factorization.
I'll pass in A, our double-precision matrix.
Now we'll need b. This is going to be a vector
of length three and we'll also put some random numbers in there, for this example.
Now, we're going to do the solve. Once you have the factorization, you can solve for a given b.
We're going to pass in a double-precision vector
Erbakan another vector tax and we'll return another vector, x.
Now, with the code, we'll want to display it so we can see it.
Let's do a Console.WriteLine() with the matrix. Let's display the matrix.
There are various ways to see the text. We'll use tab delimited so you can see rows and columns.
Then, we'll write out x
and then we'll pass in b.
Now, let's make sure we've got the right answer.
Let's write out A * x, print that out and make sure it matches
with b that the LU factorization found.
So, I'll do the product of A, our matrix, and x, our vector.
I'll need to compile and then run and see what we have.
You'll see first a 3 x 3 representation of A.
Then, x, the vector.
Then, vector b. In the final line, we're printing out A * x and you'll see it matches.
Here are some links to more information.