Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
I need to know if there is any method for norm2 and norm1 directly in c# , as you know these functions are used in math for vectors ... but is there any method in C# that can do so?
Posted

The latest .net framework 4.5 provides a method Normalize() in Vector class.
http://msdn.microsoft.com/en-us/library/system.windows.vector.normalize.aspx[^]
Have a look on the above link. There is a nice article which explains many things about vectors and vector normalization.
A Vector Type for C#[^]

If you really want a method Normalize in the previous frameworks, then use the above link, understand it and create an extension method Normalize().

public static void Normalize(this Vector vectorObj,...)
{
    /// write the normalization logic here
}


I hope you were looking for the same.
 
Share this answer
 
The Math namespace has all the methods on offer, such as Math.Round and Math.Floor. If it's not there, it's not there, and you need to write it.
 
Share this answer
 
thanks every one, unfortunately I could't fined the answer , so i start do it myself here is what I hope is right :


C#
public double norm2(double[] x)
     {
         double sum = 0;
         double norm2 = 0;
         for (int i = 0; i < x.Length; i++)
             sum = x[i] * x[i];
         norm2 = Math.Sqrt(Math.Abs(sum));
         return norm2;


     }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900