<?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/"
	>

<channel>
	<title>AB-WebLog.com&#187; math</title>
	<atom:link href="http://www.ab-weblog.com/en/tag/math/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ab-weblog.com/en</link>
	<description>Andreas Breitschopp</description>
	<lastBuildDate>Wed, 18 Mar 2015 09:47:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Math Parser for .NET</title>
		<link>http://www.ab-weblog.com/en/math-parser-for-net/</link>
		<comments>http://www.ab-weblog.com/en/math-parser-for-net/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 16:49:40 +0000</pubDate>
		<dc:creator>Andreas Breitschopp</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.ab-weblog.com/en/?p=1</guid>
		<description><![CDATA[For a new software project I&#8217;ve searched for a good math parser for .NET. Beside parsing and evaluating a formula with all common mathematical functions (like sine, cosine, logarithm, &#8230;), I additionally needed to be able to use variables inside &#8230; <a href="http://www.ab-weblog.com/en/math-parser-for-net/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For a new software project I&#8217;ve searched for a good math parser for .NET.</p>
<p>Beside parsing and evaluating a formula with all common mathematical functions (like sine, cosine, logarithm, &#8230;), I additionally needed to be able to use variables inside the formulas.</p>
<p>The best solution that I found is this one here:<br />
<a href="http://www.lundin.info/mathparser.asp" target="_blank">http://www.lundin.info/mathparser.asp</a></p>
<p>The usage is very easy; here you can see a C# example code:</p>
<pre class="brush: csharp; gutter: true">// Instantiate the parser
ExpressionParser parser = new ExpressionParser();

// Create a hashtable to hold values
Hashtable h = new Hashtable();

// Add variables and values to hashtable
h.Add("x", 1.ToString());
h.Add("y", 2.ToString());

// Parse and get the result
double result = parser.Parse("xcos(y)", h);</pre>
<p>And for those of you that prefer Visual Basic .NET:</p>
<pre class="brush: vbnet; gutter: true">' Instantiate the parser
Dim parser As New ExpressionParser()

' Create a hashtable to hold values
Dim h As New Hashtable()

' Add variables and values to hashtable
h.Add("x", 1.ToString())
h.Add("y", 2.ToString())

' Parse and get the result
Dim result As Double
result = parser.Parse("xcos(y)", h)</pre>
<p>It is important that the values are always added as String to the hashtable of variables. The reason is that internally it just injects them into the formula before parsing it &#8211; this way they have to be of type String, obviously.</p>
<p>The free assembly is open source and under the LGPL license. Therefore it can also be use in commercial projects as long as it is only linked dynamically as external library.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ab-weblog.com/en/math-parser-for-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Sine Generator for .NET</title>
		<link>http://www.ab-weblog.com/en/simple-sine-generator-for-net/</link>
		<comments>http://www.ab-weblog.com/en/simple-sine-generator-for-net/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 12:08:54 +0000</pubDate>
		<dc:creator>Andreas Breitschopp</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[sine]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.ab-weblog.com/en/?p=133</guid>
		<description><![CDATA[In this post I want to show how to create an easy sine generator in .NET. Let&#8217;s start with a code listing and then I&#8217;ll explain what I&#8217;m doing here: const double frequency = 1000; const double amplitude = 20000; &#8230; <a href="http://www.ab-weblog.com/en/simple-sine-generator-for-net/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In this post I want to show how to create an easy sine generator in .NET.</p>
<p>Let&#8217;s start with a code listing and then I&#8217;ll explain what I&#8217;m doing here:</p>
<pre class="brush: csharp; gutter: true">const double frequency	= 1000;
const double amplitude	= 20000;
const long sampleRate	= 44100;
const int durationSec	= 5;

long sampleCount = sampleRate * durationSec;

double timeStep = 1.0 / (double)sampleRate;

double time = 0;
int[] values = new int[sampleCount];
for (long i = 0; i &lt; sampleCount; i++) {
	values[i] = (int)(amplitude * Math.Sin(2 * Math.PI * frequency * time));
	time = time + timeStep;
}</pre>
<p>OK, here are some explanations:</p>
<ul>
<li>lines 1-4: some constants you can change to e. g. adjust the frequency.<br />
<em>Note:</em> the frequency cannot be more than half the sampling rate.</li>
<li>line 6: calculating the number of sampling points.</li>
<li>line 8: calculating the time between two sampling points.</li>
<li>lines 10-11: some variable initializations.</li>
<li>lines 12-15: here finally the value of each sampling point is calculated.</li>
</ul>
<p>And here is the corresponding code for Visual Basic .NET:</p>
<pre class="brush: vbnet; gutter: true">const frequency as double		= 1000
const amplitude as double		= 20000
const sampleRate As Long		= 44100
const durationSec As Integer	= 5

Dim sampleCount As Long
sampleCount = sampleRate * durationSec

Dim timeStep As Double
timeStep = 1.0 / sampleRate

Dim time As Double = 0
Dim values(0 To sampleCount - 1) As Integer
For i As Long = 0 To sampleCount - 1
	values(i) = amplitude * Math.Sin(2 * Math.PI * frequency * time)
	time = time + timeStep
Next i</pre>
<p>For sound playback you can now use either an API call like <em>PlaySound</em> (of <em>winmm.dll</em>) or the solution of <a title="Article about .NET sound class" href="http://www.codeproject.com/KB/audio-video/CPIAudio.aspx" target="_blank">this great article</a>.</p>
<p>Did you also need to generate a sine in .NET yourself already?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ab-weblog.com/en/simple-sine-generator-for-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->