<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>CenterSpace, Author at CenterSpace</title>
	<atom:link href="https://www.centerspace.net/author/centerspace/feed" rel="self" type="application/rss+xml" />
	<link>https://www.centerspace.net/author/centerspace</link>
	<description>.NET numerical class libraries</description>
	<lastBuildDate>Tue, 07 Feb 2023 21:26:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>
<site xmlns="com-wordpress:feed-additions:1">104092929</site>	<item>
		<title>Accessing .Net Libraries in SQL Server</title>
		<link>https://www.centerspace.net/accessing-net-libraries-in-sql-server</link>
					<comments>https://www.centerspace.net/accessing-net-libraries-in-sql-server#respond</comments>
		
		<dc:creator><![CDATA[CenterSpace]]></dc:creator>
		<pubDate>Thu, 12 May 2011 01:16:11 +0000</pubDate>
				<category><![CDATA[CenterSpace]]></category>
		<category><![CDATA[Corporate]]></category>
		<category><![CDATA[Marketing]]></category>
		<category><![CDATA[NMath]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=3399</guid>

					<description><![CDATA[<p>Running NMath in the SQL Server CLR using User Defined Types (UDTs) and User Defined Functions (UDFs).</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/accessing-net-libraries-in-sql-server">Accessing .Net Libraries in SQL Server</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>  In previous posts we demonstrated calling CenterSpace&#8217;s NMath libraries from Excel.  Some customers asked if we could call these libraries from Microsoft&#8217;s SQL Server so we decided to give it a shot.  It turns out the problem is a substantially harder problem to solve as the SQL environment is an order of magnitude more complex.  This post will show it is possible, but with a few caveats.</p>
<p>  There are a myriad of ways SQL Server can be setup and for this post, we took whatever shortcut we could find.  Our goal was to get this running and worry about doing it &#8220;right&#8221; later.  We found ourselves on a fairly steep learning curve without a lot of examples to work off of. Consider this more of a &#8220;proof of concept&#8221; post than the definitive &#8220;how to&#8221;.</p>
<p>  As mentioned above there are lot of different approaches to this problem.  In our minds, we wanted to see if we could couple our library at the server side and access results via Reporting Services and Report Builder. We believed that the computations would be more efficient to be handled at the server while the result could take advantage of the graphing packages in Report Services.</p>
<p>  Our approach was to build a standalone system to develop and test this work on.  We choose a standard PC platform running Windows 7.  The first task at hand was to decide which version of Microsoft SQL Server to work with.  We chose SQL Server 2008R2 full version as we needed the Report Services support.  Microsoft supplies a six month trial version that has all services available which was perfect for our project.  We installed the full version with support for the Management Studio, Report Services, and Analysis services. In addition, we downloaded Microsoft&#8217;s AdventureWorks sample databases for our testing environment.</p>
<p>  We got this all running and ran some sample scripts to make sure we had everything running correctly before moving on.  Since we were going to be developing code we installed Visual Studio 2010 next and made sure we included the necessary development templates for the SQL Server environment.</p>
<p>  After installing CenterSpace&#8217;s NMath 5.0 library, we were ready to write some code.</p>
<p>  We will start by creating a new project in Visual Studio called NMathSQL.</p>
<figure id="attachment_3404" aria-describedby="caption-attachment-3404" style="width: 500px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_01.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_01.png" alt="" title="Creating a SQL CLR project in Visual Studio" width="500" class="size-full wp-image-3404" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_01.png 927w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_01-300x213.png 300w" sizes="(max-width: 927px) 100vw, 927px" /></a><figcaption id="caption-attachment-3404" class="wp-caption-text">Creating a new SQL CLR project in Visual Studio</figcaption></figure>
<p>We then asked to pick a server and identify the database we will be using.<br />
<figure id="attachment_3406" aria-describedby="caption-attachment-3406" style="width: 400px" class="wp-caption aligncenter"><br />
<a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_02.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_02.png" alt="" title="Connecting to the Database" width="400"  class="size-full wp-image-3406" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_02.png 453w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_02-206x300.png 206w" sizes="(max-width: 453px) 100vw, 453px" /></a><figcaption id="caption-attachment-3406" class="wp-caption-text">Connecting to the Database</figcaption></figure></p>
<p>  In the next screen we will want to enable SQL/CLR debugging.</p>
<figure id="attachment_3411" aria-describedby="caption-attachment-3411" style="width: 400px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_03.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_03.png" alt="" title="Enabling SQL/CLR Debugging" width="400" class="size-full wp-image-3411" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_03.png 470w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_03-300x141.png 300w" sizes="(max-width: 470px) 100vw, 470px" /></a><figcaption id="caption-attachment-3411" class="wp-caption-text">Enabling SQL/CLR debugging</figcaption></figure>
<p>  At this point we need to start running SQL scripts as part of the overall setup. We could exit VS and perform these tasks in the Management Studio, but VS can do the job.  By selecting from the VS menu bar Data>Transact-SQL Editor>New Query Connection, we get a new window to enter scripts to be run on our database.</p>
<figure id="attachment_3414" aria-describedby="caption-attachment-3414" style="width: 500px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_04.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_04.png" alt="" title="Accessing the Transact SQL Editor " width="500" class="size-full wp-image-3414" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_04.png 839w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_04-300x173.png 300w" sizes="(max-width: 839px) 100vw, 839px" /></a><figcaption id="caption-attachment-3414" class="wp-caption-text">Accessing the Transact SQL Editor in Visual Studio</figcaption></figure>
<p>  We found it easier to copy and paste our scripts into this windows as we needed to run SQL statements.</p>
<p>  Our first task at hand is to load the assembly NMath.dll into the database we have selected to work in. It is at this point we hit our first real obstacle.  It turns out that in our shipping NMath.dll we are using some instructions to automatically load x86 or x64. These are illegal in the SQL CLR.  We were forced to remove these instructions and build an entirely separate version of NMath.dll for SQL Server.  Stepping back and looking at the big picture, we decided that this was an opportunity to also include some of the &#8220;glue&#8221; code we knew we wanted to write.  </p>
<p>  We had been looking at writing some User Defined Types (UDT) and User Defined Aggregate (UDA) functions to handle the calls into our library. It seemed to make sense to extend our libraries type definitions to be T-SQL types. The result of this approach would enable T-SQL to use NMath types such as DoubleVector and DoubleMatrix. We needed to have some way to load our new data types so we built UDAs LoadDoubleVector, LoadDoubleMatrixByRow, and LoadDoubleMatrixByColumn.  After building our new, custom NMath.dll, we can then run a script to load our assembly into the database.  </p>
<p>  Before we could do this, though, we discovered that we needed some basic assemblies that SQL server had left out of their CLR.  The following SQL script loads those assemblies.</p>
<figure id="attachment_3415" aria-describedby="caption-attachment-3415" style="width: 500px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_05.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_05.png" alt="" title="Loading Supporting Assemblies" width="500"  class="size-full wp-image-3415" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_05.png 793w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_05-300x182.png 300w" sizes="(max-width: 793px) 100vw, 793px" /></a><figcaption id="caption-attachment-3415" class="wp-caption-text">Loading Supporting Assemblies to a SQL Database</figcaption></figure>
<p>  We are now ready to run the following SQL script to load NMath for SQL.</p>
<figure id="attachment_3418" aria-describedby="caption-attachment-3418" style="width: 500px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_06.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_06.png" alt="" title="Loading NMath assembly in the SQL Database" width="500"  class="size-full wp-image-3418" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_06.png 543w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_06-300x231.png 300w" sizes="(max-width: 543px) 100vw, 543px" /></a><figcaption id="caption-attachment-3418" class="wp-caption-text">Loading NMath assembly in the SQL Database</figcaption></figure>
<p>  The next step is to add the reference to our project. From the main toolbar launch the Solution Explorer and right click on Reference then select Add Reference.  Add the new assemblies we have loaded so far.</p>
<figure id="attachment_3419" aria-describedby="caption-attachment-3419" style="width: 500px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_07.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_07.png" alt="" title="Adding NMath reference to the SQL/CLR project" width="500" class="size-full wp-image-3419" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_07.png 729w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_07-300x165.png 300w" sizes="(max-width: 729px) 100vw, 729px" /></a><figcaption id="caption-attachment-3419" class="wp-caption-text">Adding NMath reference to the SQL/CLR project</figcaption></figure>
<p>  We will now have to tell SQL about the new types and functions we have added.  We will start by adding the new UDTs DoubleVector and DoubleMatrix.</p>
<figure id="attachment_3421" aria-describedby="caption-attachment-3421" style="width: 500px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_08.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_08.png" alt="" title="SQL commands to add UDTs for LoadDoubleVector" width="500" class="size-full wp-image-3421" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_08.png 519w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_08-300x231.png 300w" sizes="(max-width: 519px) 100vw, 519px" /></a><figcaption id="caption-attachment-3421" class="wp-caption-text">SQL commands to add UDTs for LoadDoubleVector</figcaption></figure>
<p>  Now that SQL knows about our new types we can add the UDA functions with the following SQL commands.</p>
<figure id="attachment_3422" aria-describedby="caption-attachment-3422" style="width: 500px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_09.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_09.png" alt="" title="SQL Commands to add UDAs to the Database" width="500"  class="size-full wp-image-3422" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_09.png 618w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_09-300x199.png 300w" sizes="(max-width: 618px) 100vw, 618px" /></a><figcaption id="caption-attachment-3422" class="wp-caption-text">SQL Commands to add NMaths UDAs to the Database</figcaption></figure>
<p>  At this point we are ready to test our library.  We have chosen a problem that represents the work expected to be perform.  We will create our sample datapoint tables rather than use tables from the AdventureWorks database. We will then load the data from the tables into DoubleVectors and call our library using a User Defined Function(UDF). Our UDF will be a call to library to find the function values for a curve that fits our datapoints.  From our function solution we will create a table with datapoints that represent our curve function to compare against our original datapoints.</p>
<p>  We will start by creating the UDF call to our library. From the Solution Explorer, we will add a UDF template called NMathFunction.cs.</p>
<p>  Here is the C# code for this function call:</p>
<pre lang="csharp">
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using CenterSpace.NMath.Core;
using CenterSpace.NMath.Analysis;


public partial class UserDefinedFunctions
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static DoubleVector NMathFunction(DoubleVector xValues, DoubleVector yValues, DoubleVector start)
    {
        NMathFunctions.GeneralizedDoubleUnaryFunction f = AnalysisFunctions.FourParameterLogistic;
        OneVariableFunctionFitter fitter = new OneVariableFunctionFitter(f);
        return new DoubleVector(fitter.Fit(xValues, yValues, start));
    }
}
</pre>
<p>  We can now tell VS to build the assembly NmathSQL.dll and use SQL to load the assembly to our database.</p>
<figure id="attachment_3423" aria-describedby="caption-attachment-3423" style="width: 500px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_10.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_10.png" alt="" title="Loading our custom NMathFunctions to the database" width="500" class="size-full wp-image-3423" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_10.png 772w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_10-300x169.png 300w" sizes="(max-width: 772px) 100vw, 772px" /></a><figcaption id="caption-attachment-3423" class="wp-caption-text">Loading our custom NMathFunctions to the database</figcaption></figure>
<p>  In order for our UDF NmathFunction to be recognized we need to run a SQL create function command. Note that this command must be the only command in the script.  </p>
<figure id="attachment_3424" aria-describedby="caption-attachment-3424" style="width: 500px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_11.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_11.png" alt="" title="SQL Commands to Create a UDF function" width="500" class="size-full wp-image-3424" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_11.png 636w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_11-300x191.png 300w" sizes="(max-width: 636px) 100vw, 636px" /></a><figcaption id="caption-attachment-3424" class="wp-caption-text">SQL Commands to add our UDF to the database</figcaption></figure>
<p>  We have now loaded our NMath function call in the database that can be called by scripts. We are ready to write a script to solve the problem we described above.</p>
<p>  We will start by using the same data from the example we did with our excel post.</p>
<figure id="attachment_3425" aria-describedby="caption-attachment-3425" style="width: 500px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_12.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_12.png" alt="" title="Sample Data for our example" width="500" class="size-full wp-image-3425" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_12.png 602w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_12-268x300.png 268w" sizes="(max-width: 602px) 100vw, 602px" /></a><figcaption id="caption-attachment-3425" class="wp-caption-text">Sample Data for our example</figcaption></figure>
<p>  We can now build a script that uses the functionality we have built in with our library to find the solution.</p>
<pre lang="csharp">
-------------------------------------------------------
Declare @xv DoubleVector
Declare @yv DoubleVector

select @xv = dbo.LoadDoubleVector(xcol) from xvalues
select @yv = dbo.LoadDoubleVector(ycol) from yvalues

Declare @sPar DoubleVector
Declare @solution DoubleVector

set @sPar = '[ 0.1 0.1 0.1 0.1]'

select @solution = dbo.NMathFunction(@xv, @yv, @sPar)
 
select @solution.ToString()

declare @newxval float
declare @newyval float
declare @inc float
declare @a float
declare @b float
declare @c float
declare @d float

set @a = dbo.DVItem(@solution, 0)
set @b = dbo.DVItem(@solution, 1)
set @c = dbo.DVItem(@solution, 2)
set @d = dbo.DVItem(@solution, 3)
 
create table SolutionTBL (newxval float, newyval float)
	set @newxval = 0
	 
	while @newxval < 35.10
	begin
	   
	    set @newyval = @d+((@a-@d)/(1+POWER((@newxval/@c), @b)))
			     
	    insert into SolutionTBL values(@newxval, @newyval)
	    
	  set @newxval = (@newxval + 0.33)
	end
	select * from SolutionTBL
	go
---------------------------------------------------------------------
</pre>
<p>  Here is the output from this script</p>
<figure id="attachment_3427" aria-describedby="caption-attachment-3427" style="width: 500px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_13.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_13.png" alt="" title="Returned Solution from NMath library call" width="500" class="size-full wp-image-3427" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_13.png 494w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_13-239x300.png 239w" sizes="(max-width: 494px) 100vw, 494px" /></a><figcaption id="caption-attachment-3427" class="wp-caption-text">Returned Solution from NMath library call</figcaption></figure>
<p>  At this point we can pull data from tables, call our Math libraries, and put the solution in a table to be displayed. In production, this last script would be a stored procedure that would be run from the Management Studio. All of this work would reside on the SQL Server.  </p>
<p>We can now move on to the Reporting Services to see how this solution could be displayed.</p>
<p>  After launching Report Builder and establishing connection to the database. The data is accessed by setting up a dataset with a query into the table for the necessary data.</p>
<figure id="attachment_3430" aria-describedby="caption-attachment-3430" style="width: 500px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_13a.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_13a.png" alt="" title="Selecting the data in Report Builder" width="500" class="size-full wp-image-3430" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_13a.png 622w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_13a-150x150.png 150w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_13a-300x300.png 300w" sizes="(max-width: 622px) 100vw, 622px" /></a><figcaption id="caption-attachment-3430" class="wp-caption-text">Selecting the chart data in Report Builder</figcaption></figure>
<p>  From there it is merely Report Builder to build the necessary graphs.  Unfortunately, the chart wizard doesn't include scatterplots. It is best to select a chart type of Line and then run through the wizard.  After your chart is set up you can change its properties to scatterplot.</p>
<figure id="attachment_3431" aria-describedby="caption-attachment-3431" style="width: 500px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_14.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_14.png" alt="" title="Report Builder ScatterPlot" width="500" class="size-full wp-image-3431" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_14.png 962w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_14-300x209.png 300w" sizes="(max-width: 962px) 100vw, 962px" /></a><figcaption id="caption-attachment-3431" class="wp-caption-text">Report Builder ScatterPlot</figcaption></figure>
<p>  We can include our solution in the same report and generate a smooth line as we did in excel. The Report Builder is a very powerful tool which we are still learning.</p>
<figure id="attachment_3432" aria-describedby="caption-attachment-3432" style="width: 500px" class="wp-caption aligncenter"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_15.png"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2011/04/NMathSQL_15.png" alt="" title="Solution Fitted Line" width="500" class="size-full wp-image-3432" srcset="https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_15.png 939w, https://www.centerspace.net/wp-content/uploads/2011/04/NMathSQL_15-300x195.png 300w" sizes="(max-width: 939px) 100vw, 939px" /></a><figcaption id="caption-attachment-3432" class="wp-caption-text">Solution Fitted Line</figcaption></figure>
<p>  Our results are equivilent to our previous excel post and demonstrate that the approach on the SQL Server is as accurate.</p>
<p>In conclusion, we have demonstrated that we can call the CenterSpace NMath libraries from SQL Server and display the results using Report Services powerful charting capabilities.  We plan to work on more examples and compare how we might improve on what Analysis Services can produce.  We certainly will entertain feedback on useful approaches that should be examined. As a reminder this interface is not possible with our current release of NMath 5.0 and require a "special" version of our assembly.  Depending on customer interest and feedback we may or may not decide to develop a product for this interface.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/accessing-net-libraries-in-sql-server">Accessing .Net Libraries in SQL Server</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/accessing-net-libraries-in-sql-server/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3399</post-id>	</item>
		<item>
		<title>Advanced Curve Fitting using Excel and NMath</title>
		<link>https://www.centerspace.net/advanced-curve-fitting-using-excel-and-nmath</link>
					<comments>https://www.centerspace.net/advanced-curve-fitting-using-excel-and-nmath#respond</comments>
		
		<dc:creator><![CDATA[CenterSpace]]></dc:creator>
		<pubDate>Mon, 14 Mar 2011 22:10:15 +0000</pubDate>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Marketing]]></category>
		<category><![CDATA[NMath Tutorial]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=3145</guid>

					<description><![CDATA[<p>In this post, we will demonstrate the advanced curve fitting functions available in the CenterSpace libraries that could be easily be integrated into Excel analysis work. Curve fitting is one of the most practical applications of mathematics as we are often asked to explain or make predictions based on a collection of data points. This example combines the ease of Excel's charting capabilities with CenterSpace's powerful NMath library.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/advanced-curve-fitting-using-excel-and-nmath">Advanced Curve Fitting using Excel and NMath</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In recent blog posts, we have discussed how to call CenterSpace&#8217;s Libraries from Excel.  In his March 2010 blog post, CenterSpace&#8217;s Ken Baldwin demonstrated how to replicate <a href="https://www.centerspace.net">Excel&#8217;s existing Trendline functions using C# and NMath</a>.  In this post, we will demonstrate the advanced curve fitting functions available in the CenterSpace libraries that could be easily be integrated into Excel analysis work.</p>
<p>Curve fitting is one of the most practical applications of mathematics as we are often asked to explain or make predictions based on a collection of data points.  For example, if we collect a series of changing data values over time, we look to explain the relationship that time effects the generated values or in mathematical terms y=f(x).  Here we are using x to represent time values and f(x) to represent the relationship or function that generates the resulting values or y.  So if we can find a function f(x) that represents a good fit of the data we should be able to predict the result at any moment in time.</p>
<p>With this in mind, let us get started with some data points (x, y) that we have collected.  I have entered the following values in an Excel spreadsheet.</p>
<p><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/01/CurveFit1.gif"><img decoding="async" class="size-full wp-image-3146" title="Curve Fitting Sample data" src="https://www.centerspace.net/blog/wp-content/uploads/2011/01/CurveFit1.gif" width="700" alt="" srcset="https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit1.gif 777w, https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit1-300x279.gif 300w" sizes="(max-width: 777px) 100vw, 777px" /></a></p>
<p>We can now use Excel&#8217;s charting function to create the following XY scatterplot with our data:</p>
<p><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/01/CurveFit2.gif"><img decoding="async" class="size-full wp-image-3147" title="Excel XY scatterplot of sample data" width="700" src="https://www.centerspace.net/blog/wp-content/uploads/2011/01/CurveFit2.gif" alt="" srcset="https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit2.gif 1473w, https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit2-300x184.gif 300w, https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit2-1024x629.gif 1024w" sizes="(max-width: 1473px) 100vw, 1473px" /></a></p>
<p>At this point, we can add an Excel trendline to get the best fit it can provide.  By right clicking on a data value in our chart we will get the option to add a trendline. Choose a 2nd order polynomial and these options.</p>
<p>Name the trendline &#8220;2nd Order Polynomial&#8221; and check &#8220;Display equation on chart&#8221; and &#8220;Display R-squared value on chart&#8221;.</p>
<p>Excel calculates and plots the line while returning the equation and the R2 value.  If our R2 equals 1 we would have found a perfect fit.  For a second order polynomial Excel returned a value of 0.8944 which means that roughly 10.6 percent (1-.894) are not on this line.</p>
<p>If we continue increasing our polynomial orders up to the maximum of six we can achieve the best R2 value of 0.9792, but look at the curve we have fitted to these points.</p>
<p><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/01/CurveFit3.gif"><img decoding="async" class="size-full wp-image-3149" title="Excel Trendline using a polynomial function" width="700" src="https://www.centerspace.net/blog/wp-content/uploads/2011/01/CurveFit3.gif" alt="" srcset="https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit3.gif 1167w, https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit3-300x188.gif 300w, https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit3-1024x642.gif 1024w" sizes="(max-width: 1167px) 100vw, 1167px" /></a></p>
<p>A better fit might be an exponential function so let us try Excel&#8217;s trendline option using exponentials.<br />
<a href="https://www.centerspace.net/blog/wp-content/uploads/2011/01/CurveFit4.gif"><img decoding="async" class="alignnone size-full wp-image-3150" title="Excel exponential trendline fit of sample data" src="https://www.centerspace.net/blog/wp-content/uploads/2011/01/CurveFit4.gif" width="700"  alt="" srcset="https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit4.gif 1169w, https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit4-300x203.gif 300w, https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit4-1024x695.gif 1024w" sizes="(max-width: 1169px) 100vw, 1169px" /></a></p>
<p>Clearly the results are visually a better fit but the R2 value tells us that over 15% of the data points are not on this line.  This pretty much represents the best we can do with Excel&#8217;s trendline functions for our data.</p>
<p>Looking to CenterSpace&#8217;s NMath and NStat libraries to give us more robust analysis, we can utilize more powerful curve fitting tools quickly and with little effort.</p>
<p>Using the linkage provided by ExcelDNA that we examined in our previous posts, we can create the following C# code for our ExcelDNA text file.</p>
<pre lang="csharp"><![CDATA[

using System;
using ExcelDna.Integration;
using CenterSpace.NMath.Core;
using CenterSpace.NMath.Matrix;
using CenterSpace.NMath.Analysis;
using CenterSpace.NMath.Stats;

public class NMathExcelCurveFit
{

 [ExcelFunction(Description="Four parameterized Fit")]
 public static double[] NOneVarFunctFitFour(double[] xValues, double[] yValues, double[] start)
 {
  DoubleVector TempVx = new DoubleVector(xValues);
  DoubleVector TempVy = new DoubleVector(yValues);
  DoubleVector TempVs = new DoubleVector(start);
  OneVariableFunctionFitter
<TrustRegionMinimizer> fitter = new  OneVariableFunctionFitter
<TrustRegionMinimizer>( AnalysisFunctions.FourParameterLogistic );
  DoubleVector solution = fitter.Fit(TempVx, TempVy, TempVs);
  return solution.ToArray();
 }

 [ExcelFunction(Description="Four parameterized R2")]
 public static double NOneVarFunctFitFourR2(double[] xValues, double[] yValues, double[] start)
 {
  DoubleVector TempVx = new DoubleVector(xValues);
  DoubleVector TempVy = new DoubleVector(yValues);
  DoubleVector TempVs = new DoubleVector(start);
  OneVariableFunctionFitter
<TrustRegionMinimizer> fitter = new  OneVariableFunctionFitter
<TrustRegionMinimizer>( AnalysisFunctions.FourParameterLogistic );
  DoubleVector solution = fitter.Fit(TempVx, TempVy, TempVs);
  GoodnessOfFit gof = new GoodnessOfFit(fitter, TempVx, TempVy, solution);
  return gof.RSquared;
 }
}
]]&gt;</pre>
<p>As you can see by the code, I have chosen to use NMath&#8217;s OneVariableFunctionFitter with the FourParameterLogistic predefined generalized function.</p>
<pre class="code">
<img decoding="async" title="{d} + \frac{(a - d)}{ 1 + ({\frac{x}c})^b}" src="http://latex.codecogs.com/gif.latex?{d} + \frac{(a - d)}{ 1 + ({\frac{x}c})^b}" alt=""/></pre>
<p>From CenterSpace&#8217;s documentation, we get the above equation and need to solve for the model parameters <code> a, b, c, d </code>.</p>
<p>The OneVariableFunction call will require us to provide a starting guess along with the ranges containing the xValues and yValues.  The following screen shows us making the function call from Excel with the necessary parameters.</p>
<p><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/01/CurveFit6.gif"><img decoding="async" class="size-full wp-image-3156" title="CurveFit6" src="https://www.centerspace.net/blog/wp-content/uploads/2011/01/CurveFit6.gif" width="700" alt="" srcset="https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit6.gif 1296w, https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit6-300x172.gif 300w, https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit6-1024x587.gif 1024w" sizes="(max-width: 1296px) 100vw, 1296px" /></a></p>
<p>After computing these values, we can call for the R2 value and generate some points to be plotted.</p>
<p><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/01/CurveFit7.gif"><img decoding="async" class="size-full wp-image-3157" title="Obtaining the R2 value from a NMath OneVariableFunction call" src="https://www.centerspace.net/blog/wp-content/uploads/2011/01/CurveFit7.gif" width="700" alt="" srcset="https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit7.gif 1059w, https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit7-300x175.gif 300w, https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit7-1024x600.gif 1024w" sizes="(max-width: 1059px) 100vw, 1059px" /></a></p>
<p>Note that I choose to hide the rfows from r17 to r107 for display purposes. You will need to have them unhid for the chart to look right.  As you can see we returned the best R2 value so far at 0.9923.</p>
<p>In the next screen, we will have added the series to our chart and drawn a line through our calculated points.</p>
<p><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/01/CurveFit8.gif"><img decoding="async" class="size-full wp-image-3158" title="OneVariableFunction using FourParameterLogistic function plot" src="https://www.centerspace.net/blog/wp-content/uploads/2011/01/CurveFit8.gif" width="700" alt="" srcset="https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit8.gif 1179w, https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit8-300x200.gif 300w, https://www.centerspace.net/wp-content/uploads/2011/01/CurveFit8-1024x682.gif 1024w" sizes="(max-width: 1179px) 100vw, 1179px" /></a></p>
<p>This example illustrates the ease that Excel can use the power of NMath curve fitting routines to compute accurate fits to a collection of data.</p>
<p>Mike Magee</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/advanced-curve-fitting-using-excel-and-nmath">Advanced Curve Fitting using Excel and NMath</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/advanced-curve-fitting-using-excel-and-nmath/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3145</post-id>	</item>
		<item>
		<title>Absolute value of complex numbers</title>
		<link>https://www.centerspace.net/absolute-value-of-complex-numbers</link>
					<comments>https://www.centerspace.net/absolute-value-of-complex-numbers#comments</comments>
		
		<dc:creator><![CDATA[CenterSpace]]></dc:creator>
		<pubDate>Tue, 08 Mar 2011 19:51:14 +0000</pubDate>
				<category><![CDATA[MKL]]></category>
		<category><![CDATA[NMath]]></category>
		<category><![CDATA[abs complex number]]></category>
		<category><![CDATA[absolute value of a complex number]]></category>
		<category><![CDATA[BLAS absolute value]]></category>
		<category><![CDATA[MKL absolute value]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=3277</guid>

					<description><![CDATA[<p><img class="excerpt" src="http://latex.codecogs.com/gif.latex?\left &#124;x \right &#124;_{l_1} = \left &#124;x_r \right &#124; + \left &#124;x_c \right &#124;" title="\left &#124;x \right &#124; = \left &#124;x_r \right &#124; + \left &#124;x_c \right &#124;" />  Max from <a href="http://www.slb.com/">Schlumberger</a> Fiber Optics came to us with an interesting bug report regarding the <tt>MaxAbsValue()</tt> and <tt>MaxAbsIndex()</tt> functions as applied to complex vectors in the <tt>NMathFunctions</tt> class.  Most of the time these methods worked as expected, but they would intermittently fail to correctly identify the maximum element in large vectors with similar elements.  The issue turned out to be the unusual definition for the absolute value of a complex number in the BLAS standard. </p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/absolute-value-of-complex-numbers">Absolute value of complex numbers</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Max Hadley from <a href="http://www.slb.com/">Schlumberger</a> in Southampton, UK came to us with an interesting bug report regarding the <tt>MaxAbsValue()</tt> and <tt>MaxAbsIndex()</tt> functions as applied to complex vectors in the <tt>NMathFunctions</tt> class.  Most of the time these methods worked as expected, but they would intermittently fail to correctly identify the maximum element in large vectors with similar elements.</p>
<p>In researching the MKL documentation we found that this was in fact not a problem from MKL&#8217;s <a href="http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/mklxe/mkl_manual_win_mac/bla/functn_iamax.htm">perspective</a>.  MKL uses the L1-norm, or <a href="https://en.wikipedia.org/wiki/Taxicab_geometry">Manhattan distance</a> from 0,  as a metric to compute the absolute value of a complex number.  This simply means that it adds together the absolute values of the real and imaginary components:</p>
<table style="margin-left: 120px; padding: 5px;">
<tr>
<td ><img decoding="async" src="http://latex.codecogs.com/gif.latex?\left |x \right |_{l_1} = \left |x_r \right | + \left |x_c \right |" title="\left |x \right | = \left |x_r \right | + \left |x_c \right |" /></td>
</tr>
</table>
<table style="margin-left: 5px; margin-top: -30px"><center></p>
<caption align="bottom" style="padding: 5px;">Absolute value of a complex number according to BLAS.</caption>
<p></center></p>
</table>
<p>We had expected the absolute value to be computed via the L2-norm, or <a href="https://en.wikipedia.org/wiki/Euclidean_distance">Euclidean distance</a> from zero, which is referred to in places as the <a href="http://mathworld.wolfram.com/VectorNorm.html">magnitude</a> metric.  Interestingly, MKL uses the L1-norm because that is the norm defined by the underlying BLAS standard, and apparently the original designers of BLAS choose that norm for computational efficiency.  This means that all BLAS-based linear algebra packages compute the norm of a complex vector in this way &#8211; and it&#8217;s probably not what most people expect.</p>
<p>This was a tricky bug to find for two reasons.  First, substituting one norm for the other did not elicit incorrect behavior often because the real component generally dominates the magnitude.  Second, the actual calculation of the absolute value of a complex number (rather than the maximum absolute value of a complex vector) has always been calculated using the L2-norm.</p>
<p>Now that we found the problem, we faced the unenviable task of trying to make our API consistent while interfacing with MKL and how it deals with finding the maximum absolute value element in a vector of complex numbers.  We started by suffixing all complex versions of min and max abs methods that use MKL and therefore use the L1-norm to compute the absolute value of complex numbers with a &#8216;1&#8217;:</p>
<pre lang="csharp">public static int MaxAbs1Index( FloatComplexVector v )
public static int MaxAbs1Value( FloatComplexVector v )
public static int MinAbs1Index( FloatComplexVector v )
public static int MinAbs1Value( FloatComplexVector v )
public static int MaxAbs1Index( DoubleComplexVector v )
public static int MaxAbs1Value( DoubleComplexVector v )
public static int MinAbs1Index( DoubleComplexVector v )
public static int MinAbs1Value( DoubleComplexVector v )</pre>
<p>And we have subsequently written new methods that compute the maximum and minimum absolute values of a complex vector according to the L2-norm, or Euclidean distance, of its elements.  Users should be aware that these methods do not use MKL:</p>
<pre lang="csharp">public static int MaxAbsIndex( FloatComplexVector v )
public static int MaxAbsValue( FloatComplexVector v )
public static int MinAbsIndex( FloatComplexVector v )
public static int MinAbsValue( FloatComplexVector v )
public static int MaxAbsIndex( DoubleComplexVector v )
public static int MaxAbsValue( DoubleComplexVector v )
public static int MinAbsIndex( DoubleComplexVector v )
public static int MinAbsValue( DoubleComplexVector v )</pre>
<p>We hope the change is intuitive and useful.</p>
<p>Darren</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/absolute-value-of-complex-numbers">Absolute value of complex numbers</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/absolute-value-of-complex-numbers/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3277</post-id>	</item>
		<item>
		<title>Using C# and ExcelDNA to call .NET Libraries</title>
		<link>https://www.centerspace.net/using-c-and-exceldna-to-call-net-libraries</link>
					<comments>https://www.centerspace.net/using-c-and-exceldna-to-call-net-libraries#comments</comments>
		
		<dc:creator><![CDATA[CenterSpace]]></dc:creator>
		<pubDate>Fri, 14 Jan 2011 05:00:21 +0000</pubDate>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[NMath Tutorial]]></category>
		<category><![CDATA[c# math with excel]]></category>
		<category><![CDATA[Calling Excel from NMath]]></category>
		<category><![CDATA[Curve fitting with Excel]]></category>
		<category><![CDATA[ExcelDNA math]]></category>
		<category><![CDATA[ExcelDNA NMath]]></category>
		<category><![CDATA[NMath Excel]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=3058</guid>

					<description><![CDATA[<p><img src="https://www.centerspace.net/blog/wp-content/uploads/2011/01/Blog2pic2.gif" alt="Excel and NMath interop"  class="excerpt" /><br />
The outcome of these blog articles should illustrate that Excel can become a powerful tool to quickly access a comprehensive .NET library without needing a large supporting programming environment.  This made possible by Govert van Drimmelen's freeware tool ExcelDNA.  ExcelDNA can interpret VB, C#, and F# instructions stored in a text file as Excel is loaded eliminating the need for a separate compiler.  In our last blog, we named our file <strong>NMathExcel.dna</strong> to hold our VB code.  Below, I have provided C# code that performs the same matrix functions as the VB code in our <a href="https://www.centerspace.net/blog/nmath/calling-external-net-libraries-from-excel/">previous post</a>.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/using-c-and-exceldna-to-call-net-libraries">Using C# and ExcelDNA to call .NET Libraries</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In my <a href="/calling-external-net-libraries-from-excel/">last post</a>, I demonstrated calling NMath from Excel using ExcelDNA and Visual Basic (VB) code.  In this blog post, we will duplicate that functionality using C# instead of Visual Basic.  In addition we will use the functionality of NMath to enabled the marshaling of data between Excel and NMath, and provide some additional code examples.</p>
<p>The outcome of these blog articles should illustrate that Excel can become a powerful tool to quickly access a comprehensive .NET library such as CenterSpace&#8217;s NMath without needing a large supporting programming environment.  This is all made possible by Govert van Drimmelen&#8217;s freeware tool ExcelDNA.  ExcelDNA can interpret VB, C#, and F# instructions stored in a text file as Excel is loaded eliminating the need for a separate compiler.  ExcelDNA does require the text file to have the extension <code>.DNA</code>.  I recommend using an editor like <a href="https://notepad-plus-plus.org/">NotePad++</a> to edit this file.  In our last blog post, we named our file <strong>NMathExcel.dna</strong> to hold our VB code.  Below, I have provided C# code that performs the same functions as the VB code in our <a href="/calling-external-net-libraries-from-excel/">previous post</a>.  This code below provides examples on how to use several basic routines in NMath.</p>
<pre lang="csharp">

<DnaLibrary Language="CS">
<Reference Name="CenterSpace.NMath.Core" />
<Reference Path="C:\Program Files\CenterSpace\NMath 4.1\Assemblies\NMath.dll" />
<Reference Path="C:\Program Files\CenterSpace\NMath 4.1\Assemblies\NMathShared.dll" />
<Reference Name="CenterSpace.NMath.Stats" />
<Reference Path="C:\Program Files\CenterSpace\NMath Stats 3.2\Assemblies\NMathStats.dll" />

<![CDATA[
 	 using ExcelDna.Integration;
 	 using CenterSpace.NMath.Core;
  	 using CenterSpace.NMath.Stats;

  	public class NMathExcelFunctions
  	{
  		[ExcelFunction(Description="Returns x raised to the y power")]
  		public static double NPower(double x, double y)
  		{
  			return NMathFunctions.PowFunction(x, y);
  		}
  		[ExcelFunction(IsVolatile=true)]
  		public static double NRand()
  		{
  			RandGenMTwist randomGenMTwist = new RandGenMTwist();
  			return randomGenMTwist.Next53BitRes();
  		}
  		[ExcelFunction(Description="Binomial Distribution: Number of Successes, Trials, Probability, Cumulative is True or False")]
  		public static double NBinomDist(int NSuccess, int NTrials, double Prob, bool Cumul)
  		{
 	 		BinomialDistribution binomialDistribution = new BinomialDistribution();
  			binomialDistribution.N = NTrials;
  			binomialDistribution.P = Prob;
  			if (Cumul)
  				return binomialDistribution.CDF(NSuccess);
  			else
  				return binomialDistribution.PDF(NSuccess);
  		}
  		[ExcelFunction(Description="Create a r by c matrix and fill with Random # between L and B")]
  		public static double[,] NDoubleMatrixRand(int rsize, int csize, int RandLBx, int RandUBx)
  		{
  			RandGenUniform randomGenUniform = new RandGenUniform(RandLBx,RandUBx);
  			randomGenUniform.Reset(0x124);
  			DoubleMatrix TempAr = new DoubleMatrix(rsize,csize,randomGenUniform);
  			return TempAr.ToArray();
  		}
  	}
]]&gt;
</DnaLibrary>
</pre>
<p>In reviewing the differences between the VB and C# versions, the first order of business was to add the language specification to &#8220;CS&#8221; for C# so that ExcelDNA knows to switch from the default language of VB. Aside from the obvious differences between the two languages, we have added a reference to our NMathShared assembly and an explicit reference to using ExcelDNA.Integration.  In general, the C# code is slightly simpler than VB and enables very simple code to call the library.  In our C# sample code function for creating a <code>DoubleMatrix</code> with a random generation, we used the library&#8217;s built in conversion function <code>ToArray()</code> to marshal the data into an array format for Excel.  Using NMath&#8217;s built-in array handling capabilities we can simply copy data in and out in the proper formats.  This illustrates the ease by which we can utilize the NMath math libraries and Excel.</p>
<p>To further demonstrate this capability, we can add the following code to our NMathExcel.dna text file that calls the matrix transpose function in NMath.  We will show how to create array data in Excel, pass it to the library in the proper format, and then return a result for display.</p>
<pre lang="csharp">
   public static double[,] NDoubleMatrixTranspose(double[,] InputAr)
   {
      DoubleMatrix TempAr = new DoubleMatrix(InputAr);
     TempAr = TempAr.Transpose();
      return TempAr.ToArray();
   }
</pre>
<p>Make sure you close Excel and reopen it after saving your code changes to the .DNA file so that ExcelDNA has the opportunity to incorporate the new code.</p>
<p>We can now send our library a range of data cells to be acted on and display the result.  In the following screen shot I show setting up a 5 by 5 range with values to be transposed.</p>
<p><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/01/Blog2pic1.gif"><img decoding="async" loading="lazy" width="829" height="603" src="https://www.centerspace.net/blog/wp-content/uploads/2011/01/Blog2pic1.gif" alt="" title="Creating a 5x5 matrix with data" class="alignnone size-full wp-image-3071" srcset="https://www.centerspace.net/wp-content/uploads/2011/01/Blog2pic1.gif 829w, https://www.centerspace.net/wp-content/uploads/2011/01/Blog2pic1-300x218.gif 300w" sizes="(max-width: 829px) 100vw, 829px" /></a></p>
<p>We can now select an available empty cell to insert our transpose computation.  The following screenshot shows selecting the input range for calling our NMath transpose function.</p>
<p><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/01/Blog2pic2.gif"><img decoding="async" loading="lazy" width="993" height="698" src="https://www.centerspace.net/blog/wp-content/uploads/2011/01/Blog2pic2.gif" alt="" title="Selecting a range of value to send to the Transpose function  class="alignnone size-full wp-image-3073" srcset="https://www.centerspace.net/wp-content/uploads/2011/01/Blog2pic2.gif 993w, https://www.centerspace.net/wp-content/uploads/2011/01/Blog2pic2-300x210.gif 300w" sizes="(max-width: 993px) 100vw, 993px" /></a></p>
<p>As in our previous blog, the returned result is stored in a single cell and only one value is displayed.  As a quick review to display the full result, first paint (select) the area for the data to be displayed with the function call in the upper left hand corner, then press the F2 key, next press Ctrl-Shift (hold), followed by the Enter key &#8211; this will build the array formula to populate the selected area with the result.  Your result should look like the following screen.</p>
<p><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/01/Blog2pic3.gif"><img decoding="async" loading="lazy" width="773" height="555" src="https://www.centerspace.net/blog/wp-content/uploads/2011/01/Blog2pic3.gif" alt="" title="Completed example of the matrix transpose function" class="alignnone size-full wp-image-3074" srcset="https://www.centerspace.net/wp-content/uploads/2011/01/Blog2pic3.gif 773w, https://www.centerspace.net/wp-content/uploads/2011/01/Blog2pic3-300x215.gif 300w" sizes="(max-width: 773px) 100vw, 773px" /></a></p>
<p>As a further example of what is possible, we can tackle an least squares example from the NMath documentation.  The problem is to calculate the residual norm square using the Cholesky method, something that would be awkward to do natively in Excel alone. In this example the inputs are the number of rows and columns of a <code>DoubleMatrix</code> uniformly filled with random numbers. To accomplish this we need to add the following code to our DNA text file.</p>
<pre lang="csharp">
using CenterSpace.NMath.Matrix;
  .
  .
public static object NDoubleCholeskyLeastSqRNS(int rsize, int csize, int RandLBx, int RandUBx)
{
	RandGenUniform randomGenUniform = new RandGenUniform(RandLBx,RandUBx);
	randomGenUniform.Reset(0x124);
	DoubleMatrix TempAr = new DoubleMatrix(rsize,csize,randomGenUniform);
	DoubleCholeskyLeastSq cholLsq = new DoubleCholeskyLeastSq(TempAr);
	if (cholLsq.IsGood)
	{
 		DoubleVector b = new DoubleVector(TempAr.Rows,randomGenUniform);
		DoubleVector x = cholLsq.Solve(b);
		return cholLsq.ResidualNormSqr(b);
	}
	else
		return "The random matrix doesn't have full rank";
}
</pre>
<h3> Summary </h3>
<p>Approaching the complex computations with Excel by performing the necessary computation by calling a C# library with data passed in from Excel, creates a robust approach to solving problems.   The following screenshot shows how providing our function with the input parameters from the example produces the desired result.</p>
<p><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/01/Blog2pic4.gif"><img decoding="async" loading="lazy" width="870" height="418" src="https://www.centerspace.net/blog/wp-content/uploads/2011/01/Blog2pic4.gif" alt="" title="Using the Cholesky Least Squares method in Excel to solve." class="alignnone size-full wp-image-3077" srcset="https://www.centerspace.net/wp-content/uploads/2011/01/Blog2pic4.gif 870w, https://www.centerspace.net/wp-content/uploads/2011/01/Blog2pic4-300x144.gif 300w" sizes="(max-width: 870px) 100vw, 870px" /></a></p>
<p>If we tried to implement the solution line by line in Excel, we would be loosing the power of an object language like C# and powerful third-party .NET libraries, and increasing the generation of tedious Excel code without a strong development environment. </p>
<p>To wrap up, combining Excel, ExcelDNA, and the CenterSpace&#8217;s NMath libraries can be used to quickly generate solutions to complex problems without an extensive programming environment.  In my next blog, I plan to solve a curve fitting example with this approach and using more of Excel features to display the results.</p>
<p>Mike Magee</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/using-c-and-exceldna-to-call-net-libraries">Using C# and ExcelDNA to call .NET Libraries</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/using-c-and-exceldna-to-call-net-libraries/feed</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3058</post-id>	</item>
		<item>
		<title>Calling External .NET Libraries from Excel</title>
		<link>https://www.centerspace.net/calling-external-net-libraries-from-excel</link>
					<comments>https://www.centerspace.net/calling-external-net-libraries-from-excel#comments</comments>
		
		<dc:creator><![CDATA[CenterSpace]]></dc:creator>
		<pubDate>Thu, 09 Dec 2010 06:10:05 +0000</pubDate>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Marketing]]></category>
		<category><![CDATA[NMath Stats Tutorial]]></category>
		<category><![CDATA[NMath Tutorial]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[excel interop]]></category>
		<category><![CDATA[NMath and Excel]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=2845</guid>

					<description><![CDATA[<p>There are many circumstances where you may need to access an external library of functions or routines from Excel.  For example, if you need a complex function such as fitting data to a surface, or portfolio optimization, that is not natively available in Excel.  There also may be a need to protect proprietary calculations by [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/calling-external-net-libraries-from-excel">Calling External .NET Libraries from Excel</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>There are many circumstances where you may need to access an external library of functions or routines from Excel.  For example, if you need a complex function such as fitting data to a surface, or portfolio optimization, that is not natively available in Excel.  There also may be a need to protect proprietary calculations by using user defined functions to process algorithms in a black box manner.  I was looking for a way to rapidly prototype some calculations without setting up a complex development environment.</p>
<p>Harking back to the old rule of development projects of  “two out of three”, when the three metrics are fast, cheap, and quality.  On any time limited project you only can plan to achieve two metrics, never all three. Initially I like to dive in and start with fast and cheap and work my way towards quality as necessary.  So, we&#8217;ll start with the quick and dirty approach to calling external libraries from Excel.</p>
<h3>Project Setup</h3>
<p>You must have a version of .NET Framework of 2.0 or greater.  The latest .NET version is free and easily downloaded from Microsoft.</p>
<p>You&#8217;ll also need:</p>
<ul>
<li>Excel 97 or later.</li>
<li>External library assemblies that you need to access from Excel. In our case we will use Centerspace’s <strong>NMath.dll</strong> and <strong>NMathStats.dll</strong>.</li>
<li>A freeware product called ExcelDNA written by Govert van Drimmelen that can be downloaded at <a href="https://excel-dna.net/">Excel-DNA</a> .</li>
</ul>
<p>The first order of business is to unpack the downloaded file, <strong>ExcelDNA.zip</strong>, into a working directory.  For our example, we will use <em>CenterSpaceExcel</em> as our directory name. After unpacking you should have two folders <em>Distribution</em> and <em>Source</em> in our <em>CenterSpaceExcel</em> directory.  Inside the <em>Distribution</em> folder locate the file <strong>ExcelDNA.xll</strong> and rename it to <strong>NMathExcel.xll</strong>.</p>
<p>We now need to locate in the same directory the file <strong>ExcelDna.dna</strong> and rename it to <strong>NMathExcel.dna</strong>.  Then using notepad, or your favorite code editor, and open the file <strong>NMathExcel.dna</strong>.</p>
<p>You should see the following code:</p>
<pre lang="vb">
<DnaLibrary>
<![CDATA[ 
     Public Module Module1   
       Function AddThem(x, y)      
          AddThem = x + y   
       End Function 
    End Module 
]]&gt;
</DnaLibrary></pre>
<div  mce_tmp="1">Assuming CenterSpace NMath and NStat are installed in the standard locations. Change it to read as follows and save:</div>
<pre lang="vb">
<DnaLibrary>

<Reference Name="CenterSpace.NMath.Core" />
<Reference Path="C:\Program Files\CenterSpace\NMath 4.1\Assemblies\NMath.dll" />
<Reference Name="CenterSpace.NMath.Stats" />
<Reference Path="C:\Program Files\CenterSpace\NMath Stats 3.2\Assemblies\NMathStats.dll" />

<![CDATA[
	Imports NMath = CenterSpace.NMath.Core
	Imports Stats = CenterSpace.NMath.Stats

	Public Module NMathExcel

		<ExcelFunction(Description:="Returns x to the y power")> _
	    	Function NPower(x as double, y As double) As double
			NPower = NMath.NMathFunctions.PowFunction(x, y)
		End Function

		<ExcelFunction(IsMacroType:=True, IsVolatile:=True)> _
		Function NRand() As double
			dim rand As New NMath.RandGenMTwist
			NRand = rand.Next53BitRes()
		End Function

		<ExcelFunction(Description:="Binomial Distribution: Number of Successes, Trials, Probability, Cumulative is True or False")> _
		Function NBinomDist(NSuccess As Int32, NTrials As Int32, Prob As double, Cumul As Boolean) As double
			dim nbin As New Stats.BinomialDistribution
			nbin.N = NTrials
			nbin.P = Prob
			IF Cumul
				NBinomDist = nbin.CDF(NSuccess)
			Else
				NBinomDist = nbin.PDF(NSuccess)
			End If
		End Function

		Function NDoubleMatrixRand(rsize As integer, csize As integer, RandLBx As integer, RandUBy As integer) As Object(,)
			dim rng As New NMath.RandGenUniform(RandLBx,RandUBy)
			Rng.Reset(&#038;H124)
			dim TempA As New NMath.DoubleMatrix(rsize, csize, Rng)
			NDoubleMatrixRand = NCopyArray(TempA, rsize, csize)

		End Function

		Function NCopyArray(IMatrix As Object, rsize As integer, csize As integer) As Object(,)
			dim i As Integer
			dim j As Integer
			dim OArray(rsize, csize) As Object
			for i = 0 to rsize - 1
			   for j = 0 to csize - 1
				OArray(i,j) = IMatrix(i,j)
			   next j
			next i
			NCopyArray = OArray
		End Function		

	End Module
]]&gt;</pre>
<p>We now have created the VB code to call our CenterSpace Math and Statistics libraries with the following five functions.</p>
<ol>
<li>The first function shows a simple math library call to the Power function which takes a number x and raises it to the y power and returns the value.</li>
<li>The second function shows a call to obtain a fast random number from the math library.  Since we want a new number each time the spreadsheet is re-calculated we have made the function <code>volatile</code>.</li>
<li>The third function call shows how to set values that need to be accessed by a function in our .NET assemble; in this case, the Binomial Distribution.</li>
<li>The fourth function demonstrates the creation of a <code>DoubleMatrix</code> that is the filled with random uniformly distributed numbers.</li>
<li>The fifth function is a helper sub-routine to transfer data across the com interface.</li>
</ol>
<h3>Test our setup in Excel</h3>
<p>Open Excel and move your cursor the <span style="text-decoration: underline;">Tools</span> menu item.  Usually towards the bottom of the drop down menu you will find the selection <span style="text-decoration: underline;">Add-Ins</span>.  After selecting <span style="text-decoration: underline;">Add-Ins</span>, you see the pop-up window with the option to select Microsoft supplied Add-ins.  Choose the <span style="text-decoration: underline;">Browse</span> option and go to the working directory we created at the beginning.  In our case, this will be the <em>CenterSpaceExcel</em> directory.  Next select the <em>Distribution</em> folder and you should see the renamed file: <strong>NMathExcel.xll</strong>.  Select it and you should now see the following screen.</p>
<figure id="attachment_2899" aria-describedby="caption-attachment-2899" style="width: 360px" class="wp-caption alignnone"><a href="https://www.centerspace.net/blog/wp-content/uploads/2010/12/ExcelAddin1.gif"><img decoding="async" loading="lazy" class="size-full wp-image-2899" title="ExcelAddin" src="https://www.centerspace.net/blog/wp-content/uploads/2010/12/ExcelAddin1.gif" alt="" width="360" height="422" srcset="https://www.centerspace.net/wp-content/uploads/2010/12/ExcelAddin1.gif 360w, https://www.centerspace.net/wp-content/uploads/2010/12/ExcelAddin1-255x300.gif 255w" sizes="(max-width: 360px) 100vw, 360px" /></a><figcaption id="caption-attachment-2899" class="wp-caption-text">Selecting a user created XLL as an Add-in for Excel</figcaption></figure>
<p>Make sure NMathExcel is checked and click OK. If you get an error and this point it is probably due to a typo in the DNA file, otherwise you will get the expected new sheet ready for entry.</p>
<p>Select an empty cell and then select from the menu bar <span style="text-decoration: underline;">Insert</span> then from the pulldown <span style="text-decoration: underline;">Function</span>.  You should see the following pop-up.</p>
<figure id="attachment_2902" aria-describedby="caption-attachment-2902" style="width: 540px" class="wp-caption alignnone"><a href="https://www.centerspace.net/blog/wp-content/uploads/2010/12/InsertFunction.gif"><img decoding="async" loading="lazy" class="size-full wp-image-2902" title="InsertFunction" src="https://www.centerspace.net/blog/wp-content/uploads/2010/12/InsertFunction.gif" alt="" width="540" height="423" srcset="https://www.centerspace.net/wp-content/uploads/2010/12/InsertFunction.gif 540w, https://www.centerspace.net/wp-content/uploads/2010/12/InsertFunction-300x235.gif 300w" sizes="(max-width: 540px) 100vw, 540px" /></a><figcaption id="caption-attachment-2902" class="wp-caption-text">Selecting the category containing our NMath functions</figcaption></figure>
<p>At the bottom of the category pull down you should see our NMathExcel Functions;  Select it and you should have these options.:</p>
<figure id="attachment_2905" aria-describedby="caption-attachment-2905" style="width: 540px" class="wp-caption alignnone"><a href="https://www.centerspace.net/blog/wp-content/uploads/2010/12/InsNMathFctn.gif"><img decoding="async" loading="lazy" class="size-full wp-image-2905" title="InsNMathFctn" src="https://www.centerspace.net/blog/wp-content/uploads/2010/12/InsNMathFctn.gif" alt="" width="540" height="427" srcset="https://www.centerspace.net/wp-content/uploads/2010/12/InsNMathFctn.gif 540w, https://www.centerspace.net/wp-content/uploads/2010/12/InsNMathFctn-300x237.gif 300w" sizes="(max-width: 540px) 100vw, 540px" /></a><figcaption id="caption-attachment-2905" class="wp-caption-text">NMath Excel Function Category</figcaption></figure>
<p>If we choose <code>NPower</code>, we will get the next screen,</p>
<figure id="attachment_2906" aria-describedby="caption-attachment-2906" style="width: 540px" class="wp-caption alignnone"><a href="https://www.centerspace.net/blog/wp-content/uploads/2010/12/InsNMathFctnPwrArg.gif"><img decoding="async" loading="lazy" class="size-full wp-image-2906" title="InsNMathFctnPwrArg" src="https://www.centerspace.net/blog/wp-content/uploads/2010/12/InsNMathFctnPwrArg.gif" alt="" width="540" height="359" srcset="https://www.centerspace.net/wp-content/uploads/2010/12/InsNMathFctnPwrArg.gif 540w, https://www.centerspace.net/wp-content/uploads/2010/12/InsNMathFctnPwrArg-300x199.gif 300w" sizes="(max-width: 540px) 100vw, 540px" /></a><figcaption id="caption-attachment-2906" class="wp-caption-text">Calling NMath Library Power function in Excel</figcaption></figure>
<p>I arbitrarily typed the value of 3.2 for x and 3.327 for y.  You can see the result of 47.9329301 before selecting OK.</p>
<p>Select OK and Excel will insert the value into the cell.  Select another blank cell and this time choose our <code>NRand()</code> function.  You will notice there is no opportunity to enter values and finish by selecting OK.  At this point you should see a number between 0 and 1 in the cell.  Each time you press F9 (sheet recalc) a new random number will appear.  If we had not made this function volatile the number would not change unless you edit the cell.</p>
<p>To test our Binomial Distribution function, again we will select a new cell and use the insert function option to insert the <code>NBinomDist</code> function with the following values.</p>
<figure id="attachment_2909" aria-describedby="caption-attachment-2909" style="width: 540px" class="wp-caption alignnone"><a href="https://www.centerspace.net/blog/wp-content/uploads/2010/12/InsNMathFctnBinomArg.gif"><img decoding="async" loading="lazy" class="size-full wp-image-2909" title="InsNMathFctnBinomArg" src="https://www.centerspace.net/blog/wp-content/uploads/2010/12/InsNMathFctnBinomArg.gif" alt="" width="540" height="361" srcset="https://www.centerspace.net/wp-content/uploads/2010/12/InsNMathFctnBinomArg.gif 540w, https://www.centerspace.net/wp-content/uploads/2010/12/InsNMathFctnBinomArg-300x200.gif 300w" sizes="(max-width: 540px) 100vw, 540px" /></a><figcaption id="caption-attachment-2909" class="wp-caption-text">Calling NMath Statistical function Binomial Distribution from Excel</figcaption></figure>
<p>At this point we have made successful calls into both of CenterSpace&#8217;s NMath and NMath Stats .NET math libraries.</p>
<p>In our fourth example, we will see how Excel handles matrices and look at issues passing array arguments across the COM interface.  Excel 2003 was limited to a maximum of 60,000 cells in an array, but Excel 2007 was expanded to handle 2 million.  Excel has some quirky ways of displaying matrices, and I&#8217;ll cover the in&#8217;s and out&#8217;s of these quirks.</p>
<p>We have written the basic code to set up a function called <code>NDoubleMatrixRand</code> for the purpose of creating a matrix with supplied dimensions and filled with uniform Random numbers over a specified distribution.  We will select another blank cell and again go to insert function and this time choose <code>NDoubleMatrixRand</code>.  Suppose we want to create a 6&#215;6 matrix filled with random numbers between -2 and 2.  Our input will look like the following screen.</p>
<figure id="attachment_2910" aria-describedby="caption-attachment-2910" style="width: 600px" class="wp-caption alignnone"><a href="https://www.centerspace.net/blog/wp-content/uploads/2010/12/InsDblMtrxRandArg.gif"><img decoding="async" loading="lazy" class="size-full wp-image-2910" title="InsDblMtrxRandArg" src="https://www.centerspace.net/blog/wp-content/uploads/2010/12/InsDblMtrxRandArg.gif" alt="" width="600" height="421" srcset="https://www.centerspace.net/wp-content/uploads/2010/12/InsDblMtrxRandArg.gif 600w, https://www.centerspace.net/wp-content/uploads/2010/12/InsDblMtrxRandArg-300x210.gif 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-2910" class="wp-caption-text">Creating a DoubleMatrix in Excel using NMath</figcaption></figure>
<p>Notice the equal sign in the middle right of the above screen is equal to {-0.994818527251482,-0.08</p>
<p>Values inclosed in curly brackets that are separated by commas indicates that an matrix was actually created, but you can see the Formula result is only displaying a partial value due to display size. At this point when you select OK, you will have a cell with a single value.  Here is where the fun begins.  Start at the cell and drag a 6&#215;6 range as shown in the following screen.</p>
<figure id="attachment_2911" aria-describedby="caption-attachment-2911" style="width: 564px" class="wp-caption alignnone"><a href="https://www.centerspace.net/blog/wp-content/uploads/2010/12/InsDblMtrxRandDsply.gif"><img decoding="async" loading="lazy" class="size-full wp-image-2911" title="InsDblMtrxRandDsply" src="https://www.centerspace.net/blog/wp-content/uploads/2010/12/InsDblMtrxRandDsply.gif" alt="" width="564" height="274" srcset="https://www.centerspace.net/wp-content/uploads/2010/12/InsDblMtrxRandDsply.gif 564w, https://www.centerspace.net/wp-content/uploads/2010/12/InsDblMtrxRandDsply-300x145.gif 300w" sizes="(max-width: 564px) 100vw, 564px" /></a><figcaption id="caption-attachment-2911" class="wp-caption-text">Selecting the area the matrix is to be displayed in</figcaption></figure>
<p>Now get your fingers limbered. Here is where it gets a bit obscure &#8211; do exactly as follows.</p>
<ul>
<li>Press the F2 key.  (<em>pressing F2 may be  optional but is recommended by Excel as the cell leaves the edit mode</em>)</li>
<li>Press and hold the Ctrl key followed by</li>
<li>pressing and holding the Shift key followed by</li>
<li>pressing the Enter key</li>
</ul>
<p>and presto chango!  You should see a screen like this.</p>
<figure id="attachment_2913" aria-describedby="caption-attachment-2913" style="width: 561px" class="wp-caption alignnone"><a href="https://www.centerspace.net/blog/wp-content/uploads/2010/12/InsDblMtrxRandDsplyRslt.gif"><img decoding="async" loading="lazy" class="size-full wp-image-2913" title="InsDblMtrxRandDsplyRslt" src="https://www.centerspace.net/blog/wp-content/uploads/2010/12/InsDblMtrxRandDsplyRslt.gif" alt="" width="561" height="211" srcset="https://www.centerspace.net/wp-content/uploads/2010/12/InsDblMtrxRandDsplyRslt.gif 561w, https://www.centerspace.net/wp-content/uploads/2010/12/InsDblMtrxRandDsplyRslt-300x112.gif 300w" sizes="(max-width: 561px) 100vw, 561px" /></a><figcaption id="caption-attachment-2913" class="wp-caption-text">Displaying a Matrix in Excel </figcaption></figure>
<p>Notice that your cell&#8217;s formula is now enclosed in { }, indicating to Excel that the contained formula is an array function.  This is the only way to get matrices displayed.  Also, if you try to edit this cell you will get an error that changes are not allowed.  If  you want to change the dimensions simply reference the values from another cell when you create the function.</p>
<p>The fifth function <code>NCopyArray</code> copies the library matrix across the COM bridge into an Excel array object.  As I stated in the beginning this would be a quick and dirty approach and would leave room for improvement.</p>
<h3>Summary</h3>
<p>In my next post, I will provide the above code in C# and add more function calls with some matrices with hopefully an improved approach to <code>NCopyArray</code>.  Future posts will include creating a packaged XLL and a more complex example such as curve fitting.</p>
<p>Since time is our most precious asset, being able to quickly access complex math functions with a general purpose tool like Excel should save time and money!</p>
<p>At CenterSpace, we are interested if this blog is helpful and if there is a need for more examples of how our libraries can be accessed by Excel.  Let us know what areas are of interest to you.</p>
<p>Mike  Magee</p>
<p><strong>Thanks and Resources </strong><br />
Also, a special thanks to Govert van Drimmelen for writing a wonderful tool such as ExcelDNA.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/calling-external-net-libraries-from-excel">Calling External .NET Libraries from Excel</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/calling-external-net-libraries-from-excel/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2845</post-id>	</item>
		<item>
		<title>SuperComputing 2010</title>
		<link>https://www.centerspace.net/supercomputing-2010-in-new-orleans</link>
					<comments>https://www.centerspace.net/supercomputing-2010-in-new-orleans#respond</comments>
		
		<dc:creator><![CDATA[CenterSpace]]></dc:creator>
		<pubDate>Fri, 15 Oct 2010 17:14:47 +0000</pubDate>
				<category><![CDATA[CenterSpace]]></category>
		<category><![CDATA[Marketing]]></category>
		<category><![CDATA[HC10]]></category>
		<category><![CDATA[SuperComputing 2010]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=2774</guid>

					<description><![CDATA[<p><img src="https://www.centerspace.net/blog/wp-content/uploads/2010/10/SC.jpg" alt="SC 10 log" title="SC 10"  class="excerpt" /><br />
CenterSpace Software is presenting at SuperComputing 2010 in New Orleans on November 18th.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/supercomputing-2010-in-new-orleans">SuperComputing 2010</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>CenterSpace Software will be at <a href="http://sc10.supercomputing.org/">SC 10</a> in New Orleans. Our team will be delivering a presentation at the Intel booth on November 18th at noon.  Our CEO, Trevor Misfeldt, and CTO, Paul Shirkey, will be presenting a customer success story on NMath and MKL.<br />
</br><br />
<center><img decoding="async" loading="lazy" src="https://www.centerspace.net/blog/wp-content/uploads/2010/10/SC.jpg" alt="SuperComputing 2010 logo" title="SuperComputing 2010 logo" width="204" height="130" class="size-full wp-image-2782" /></center><br />
</br><br />
If you&#8217;re attending, please join us at the presentation. We look forward to seeing you. Let us know in advance and we can schedule some time to talk about NMath, consulting, cloud computing and new features.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/supercomputing-2010-in-new-orleans">SuperComputing 2010</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/supercomputing-2010-in-new-orleans/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2774</post-id>	</item>
		<item>
		<title>Go Back to School with NMath</title>
		<link>https://www.centerspace.net/go-back-to-school-with-nmath</link>
					<comments>https://www.centerspace.net/go-back-to-school-with-nmath#respond</comments>
		
		<dc:creator><![CDATA[CenterSpace]]></dc:creator>
		<pubDate>Wed, 08 Sep 2010 20:55:50 +0000</pubDate>
				<category><![CDATA[CenterSpace]]></category>
		<category><![CDATA[Student version]]></category>
		<category><![CDATA[.NET math library]]></category>
		<category><![CDATA[centerspace news]]></category>
		<category><![CDATA[nmath student version]]></category>
		<category><![CDATA[student nmath]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=2635</guid>

					<description><![CDATA[<p>CenterSpace is offering a new NMath student edition, perfect for the student taking .NET programming courses focusing on math, statistics or engineering. <img class="excerpt" title="math_graphic" src="https://www.centerspace.net/blog/wp-content/uploads/2010/09/math_graphic1-300x176.jpg" alt="" width="218" height="111" /></p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/go-back-to-school-with-nmath">Go Back to School with NMath</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><strong>CenterSpace Software is proud to announce the release of the Student Edition of its NMath and NMath Stats numerical libraries.</strong></p>
<p>NMath Student Editions are fully functional versions of the NMath libraries that expire in one year.  Perfect for the student taking .NET programming courses focusing on math, statistics or engineering.</p>
<p>&#8220;More and more students are requesting our libraries to help them with their programming projects.&#8221; says CEO Trevor Misfeldt  &#8220;This new edition allows them to use the NMath libraries for a longer period of time at a very low cost.&#8221;</p>
<p>This year you can go back to school with NMath!</p>
<p style="text-align: center;"><a href="https://www.centerspace.net/blog/wp-content/uploads/2010/09/math_graphic1.jpg"><img decoding="async" loading="lazy" class="size-medium wp-image-2641 aligncenter" title="math_graphic" src="https://www.centerspace.net/blog/wp-content/uploads/2010/09/math_graphic1-300x176.jpg" alt="" width="218" height="111" /></a></p>
<p>Student versions are licensed for non-commerical use only, proof of student status is required after purchase and before delivery.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/go-back-to-school-with-nmath">Go Back to School with NMath</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/go-back-to-school-with-nmath/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2635</post-id>	</item>
		<item>
		<title>Join CenterSpace at the Intel Developer Forum in San Francisco!</title>
		<link>https://www.centerspace.net/join-us-at-idf-in-san-francisco</link>
					<comments>https://www.centerspace.net/join-us-at-idf-in-san-francisco#respond</comments>
		
		<dc:creator><![CDATA[CenterSpace]]></dc:creator>
		<pubDate>Wed, 08 Sep 2010 20:44:43 +0000</pubDate>
				<category><![CDATA[CenterSpace]]></category>
		<category><![CDATA[centerspace news]]></category>
		<category><![CDATA[IDF]]></category>
		<category><![CDATA[Intel developer forum]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=2643</guid>

					<description><![CDATA[<p><img class="excerpt" title="IDF2010" src="https://www.centerspace.net/blog/wp-content/uploads/2010/09/IDF20102.jpg" alt="intel developer forum"/></a>CenterSpace CEO Trevor Misfeldt, and CTO Paul Shirkey, will be attending the Intel Developer Forum...</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/join-us-at-idf-in-san-francisco">Join CenterSpace at the Intel Developer Forum in San Francisco!</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p style="text-align: left;"><a href="https://www.centerspace.net/blog/wp-content/uploads/2010/09/IDF20102.jpg"><img decoding="async" loading="lazy" class="alignleft size-full wp-image-2648" title="IDF2010" src="https://www.centerspace.net/blog/wp-content/uploads/2010/09/IDF20102.jpg" alt="intel developer forum" width="160" height="96" /></a>CenterSpace CEO Trevor Misfeldt, and CTO Paul Shirkey, will be attending the Intel Developer Forum on Sept 13th &amp; 14th in San Francisco. </p>
<p>Any one who would like to meet with them personally during their time in the Bay Area can contact Amy to schedule an appointment.  541.896.1301</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/join-us-at-idf-in-san-francisco">Join CenterSpace at the Intel Developer Forum in San Francisco!</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/join-us-at-idf-in-san-francisco/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2643</post-id>	</item>
		<item>
		<title>We&#8217;ve Moved to a New Larger Location</title>
		<link>https://www.centerspace.net/weve-moved-2</link>
					<comments>https://www.centerspace.net/weve-moved-2#respond</comments>
		
		<dc:creator><![CDATA[CenterSpace]]></dc:creator>
		<pubDate>Mon, 28 Jun 2010 23:20:37 +0000</pubDate>
				<category><![CDATA[CenterSpace]]></category>
		<category><![CDATA[centerspace news]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=2302</guid>

					<description><![CDATA[<p><img src="https://www.centerspace.net/blog/wp-content/uploads/2010/06/creesbldgsignage-300x180.jpg" alt="Crees Building Signage" title="Crees Building Signage"class="excerpt" /><br />
CenterSpace Software is excited to announce that we have moved to our new Corvallis offices.  " We were busting at the seams so it was time for a move." said CenterSpace CEO Trevor Misfeldt  "Our team is growing so we can expand the functionality of the NMath software and provide more consulting services to our customers."</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/weve-moved-2">We&#8217;ve Moved to a New Larger Location</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>CenterSpace Software is excited to announce that we have moved to our new Corvallis offices.</p>
<p>&#8221; We were busting at the seams so it was time for a move.&#8221; said CenterSpace CEO Trevor Misfeldt  &#8220;Our team is growing so we can expand the functionality of the NMath software and provide more consulting services to our customers.&#8221;</p>
<p>Our new location is located on the third floor of the historic Crees Building in downtown Corvallis Oregon. </p>
<blockquote>
<table>
<tr>
<td>CenterSpace Software </td>
</tr>
<tr>
<td>230 SW 3rd Street, Suite #311</td>
</tr>
<tr>
<td>Corvallis OR, 97333</td>
</tr>
<tr>
<td> +1.541.896.1301</td>
</tr>
</table>
</blockquote>
<figure id="attachment_2316" aria-describedby="caption-attachment-2316" style="width: 350px" class="wp-caption alignright"><a href="https://www.centerspace.net/blog/wp-content/uploads/2010/06/creesbldgfrontaddress.jpg"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2010/06/creesbldgfrontaddress.jpg" alt="Crees Building front address" title="Crees Building front address" width="350" class="size-full wp-image-2316" srcset="https://www.centerspace.net/wp-content/uploads/2010/06/creesbldgfrontaddress.jpg 793w, https://www.centerspace.net/wp-content/uploads/2010/06/creesbldgfrontaddress-300x138.jpg 300w" sizes="(max-width: 793px) 100vw, 793px" /></a><figcaption id="caption-attachment-2316" class="wp-caption-text">Art Deco Crees Building Front Address</figcaption></figure>
<p>At the time of its construction in 1926, the Crees Building was the largest commercial building to ever be built in downtown Corvallis and it has played a major role in the commerce of the area.   Visitors can take a ride to our offices on the third floor in the oldest working (we hope!) elevator in Corvallis.<br />
<figure id="attachment_2334" aria-describedby="caption-attachment-2334" style="width: 200px" class="wp-caption alignright"><a href="https://www.centerspace.net/blog/wp-content/uploads/2010/06/creesbldgsignage.jpg"><img decoding="async" src="https://www.centerspace.net/blog/wp-content/uploads/2010/06/creesbldgsignage-300x180.jpg" alt="Crees Building Signage" title="Crees Building Signage" width="200"  class="size-medium wp-image-2334" srcset="https://www.centerspace.net/wp-content/uploads/2010/06/creesbldgsignage-300x180.jpg 300w, https://www.centerspace.net/wp-content/uploads/2010/06/creesbldgsignage.jpg 800w" sizes="(max-width: 300px) 100vw, 300px" /></a><figcaption id="caption-attachment-2334" class="wp-caption-text">Crees Building Signage</figcaption></figure></p>
<p>&#8220;With almost twice the square footage of our former location, we will not only be able to handle the growth of our staff but also provide a unique environment for our new series of quarterly training classes starting in August 2010.&#8221; says Misfeldt.</p>
<p><strong>About CenterSpace Software</strong><br />
CenterSpace Software is a leading provider of enterprise class numerical component libraries for the .NET platform. Developers worldwide use CenterSpace products to develop .NET financial, engineering, and scientific applications. CenterSpace Software has offices in Corvallis, OR, and can be found on the Internet at <a href="https://www.centerspace.net/">https://www.centerspace.net</a>.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/weve-moved-2">We&#8217;ve Moved to a New Larger Location</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/weve-moved-2/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2302</post-id>	</item>
	</channel>
</rss>
