OverviewUse the built-in mathematical functions and objects to efficiently create numerical algorithms in C# or Visual Basic. Store and manipulate large data sets in arrays. Make sure to use the suggested expressions to optimize memory and speed. The syntax is kept clear and simple. If you have already worked with MATLAB or Octave, it will be very easy to get used to the Computing Engine. Getting startedIn Visual Studio create a newConsole Application. Right-click the target project in the Solution Explorer. On the project menu, click Add new Item. Select the item templateComputing Module in the Templates pane. Double clickProperties and set your Computing Module as Startup object. Replace the body of SimpleMethod() with the following code:
C# Edit|Remove csharppublic static ILRetArray<double> SimpleMethod(ILInArray<double> A, ILInArray<double> B) { using (ILScope.Enter(A, B)) { // Hello ILNumerics: a simple matrix inversion // make a copy of input matrix A: ILArray<double> C = A.C; // B is added to the first and last row of C C["0,end;:"] = C["0,end;:"] + B; // C is inverted and returned: ILArray<double> rhs = eye(C.S[0], C.S[1]); ILArray<double> ret = linsolve(C, rhs); return ret; }} public static ILRetArray<double> SimpleMethod(ILInArray<double> A, ILInArray<double> B) { using (ILScope.Enter(A, B)) { // Hello ILNumerics: a simple matrix inversion // make a copy of input matrix A: ILArray<double> C = A.C; // B is added to the first and last row of C C["0,end;:"] = C["0,end;:"] + B; // C is inverted and returned: ILArray<double> rhs = eye(C.S[0], C.S[1]); ILArray<double> ret = linsolve(C, rhs); return ret; } } Add the following lines to the Main function and hitF5to run the program.
C# Edit|Remove csharp/// <summary> /// Example method showing the utilization of the computing module /// </summary>public static void Main(params string[] parameter) { ILArray<double> Matrix = rand(1000, 1000); ILArray<double> Inverse = SimpleMethod(Matrix, 10); Console.WriteLine(Inverse["0:4;0:4"]); } /// <summary> /// Example method showing the utilization of the computing module /// </summary> public static void Main(params string[] parameter) { ILArray<double> Matrix = rand(1000, 1000); ILArray<double> Inverse = SimpleMethod(Matrix, 10); Console.WriteLine(Inverse["0:4;0:4"]); } As a result, the first five elements of the first five rows are printed to the console. C# Edit|Remove csharp<Double> [5,5] 0,2987 0,2315 -0,3078 0,7414 1,0811 -0,0504 -0,0733 0,0870 -0,1963 -0,2840 0,0258 0,0632 0,0339 0,3719 0,5363 -0,1301 -0,0820 0,2416 -0,5147 -0,5916 -0,2074 -0,1716 0,2962 -0,5045 -0,7561 <Double> [5,5] 0,2987 0,2315 -0,3078 0,7414 1,0811 -0,0504 -0,0733 0,0870 -0,1963 -0,2840 0,0258 0,0632 0,0339 0,3719 0,5363 -0,1301 -0,0820 0,2416 -0,5147 -0,5916 -0,2074 -0,1716 0,2962 -0,5045 -0,7561 ArraysCreate ILArrays of different data types. Create arrays of different shapes: e.g. row vectors. Extract information about your array. Manipulate your array by changing its shape. Access specific elements, either by using strings ... or variables. Perform arithmetic operations on arrays of different shapes. Built-in mathematical functionsThe Computing Engine provides a set of basic and more sophisticated mathematical functions. Clickhere to get an overview. ToolboxesAnd there are more functions. Click on the links below to get more details on: General usageTo benefit from the optimization and efficient memory management the Computing Engine offers, you should follow the general usage rules. Read this tutorial, to learn about expressions you should use or waive. More information |