Last active
March 21, 2017 12:19
Star
You must be signed in to star a gist
Aritmetical operations in array is impossible in C#. Using MathDot like algebraic libraries are known, however, it is not allowed in SQLServer CLR. To circumwent I've developed pure C# function to operate arrays.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace LinearAlgebraExperiment | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
float[] a = new float[] {10,20,30 }; | |
float[] b = new float[] { 10, 20, 30 }; | |
float[] c=multiply_array(a, b,"+"); | |
Console.ReadLine(); | |
} | |
/// <summary> | |
/// Multiplies array with single scalar | |
/// </summary> | |
/// <param name="a"></param> | |
/// <param name="b"></param> | |
/// <param name="opsign"></param> | |
/// <returns></returns> | |
public static float[] array_multiple_scalar(float[] a, float b) | |
{ | |
int i = 0; | |
float[] c = new float[a.Length]; | |
while (i < a.Length) | |
{ | |
float elma = 0; | |
elma = a[i]; | |
c[i] = elma*b; | |
i = i + 1; | |
} | |
return (c); | |
} | |
/// <summary> | |
/// Operation with two array | |
/// </summary> | |
/// <param name="a"></param> | |
/// <param name="b"></param> | |
/// <param name="opsign"></param> | |
/// <returns></returns> | |
public static float[] array_aritmetic(float[] a, float[] b, string opsign) | |
{ | |
int i = 0; | |
float[] c = new float[a.Length]; | |
while (i < a.Length) | |
{ | |
Console.WriteLine(i); | |
float elma = a[i]; | |
float elmb = b[i]; | |
float elmc = 0; | |
if (opsign == "+") | |
{ | |
elmc = elma + elmb; | |
} | |
else if (opsign == "-") | |
{ | |
elmc = elma - elmb; | |
} | |
else if (opsign == "*") | |
{ | |
elmc = elma * elmb; | |
} | |
c[i] = elmc; | |
i = i + 1; | |
} | |
return (c); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment