0% found this document useful (0 votes)
5 views

Program.cs

Uploaded by

spare17012002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Program.cs

Uploaded by

spare17012002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

4/16/25, 2:30 PM Program.

cs

LibTestApp\Program.cs

1 using System;
2
3 class Program
4 {
5 static void Main(string[] args)
6 {
7 Console.WriteLine("Testit");
8
9 // when we instantiate a new vector, we use the "new" command
10 Vex v1 = new Vex(2.2, -1.1, 3.3);
11 Console.WriteLine("vector v1: " + v1);
12
13 Vex v2 = new Vex(3.0, 2.0, -1.0);
14 Console.WriteLine("Vector v2: " + v2 + "\n");
15
16 // we can access individual elements of a vector
17 Console.WriteLine("z element: " + v1.z);
18 v1.z = 5.5;
19 Console.WriteLine("Modified Vector v1: " + v1 + "\n");
20
21
22 // We can multiply a vector by a scalar on the left
23 Vex scalarVecProduct = 3.0*v2;
24 // Note that I didn't need to call the "new" command because Vex functions
25 // and operators do the instantiation for us.
26 Console.WriteLine("Scalar vector product: " + scalarVecProduct);
27
28 // Can also multiply by scalar on the right
29 Vex vecScalarProduct = v2*4.0;
30 Console.WriteLine("Vector scalar product: " + vecScalarProduct + "\n");
31
32 // We can add and subtract vectors
33 Vex sum = v1 + v2;
34 Vex diff = v1 - v2;
35 Console.WriteLine("sum: " + sum);
36 Console.WriteLine( "diff:" + diff);
37
38 // Linear combination of vectors
39 Vex lc = 3.1*v1 - 4.2*v2;
40 Console.WriteLine("Linear Combination: " + lc + "\n");
41
42 // Dot product, this produces a scalar
43 double dotProd = Vex.Dot(2.0*v2, v1);
44 // Cross Product
45 Vex crossProd = Vex.Cross(v1, v2);
46 // Triple Cross Product
47 Vex tripCrossProduct = Vex.Cross(v1, Vex.Cross(v1, v2));
48 Console.WriteLine("Dot product: " + dotProd);
49 Console.WriteLine("Cross product: " + crossProd);
50 Console.WriteLine("Triple product: " + tripCrossProduct + "\n\n");
51
52 // System of liner algebraic equations
53 LinSysEq sys;
54 sys = new LinSysEq(3); // instantiate with 3 equations and 3 unknowns
localhost:62027/8c379852-860d-4e98-a8e3-9ee3361b692c/ 1/2
4/16/25, 2:30 PM Program.cs
55
56 // Set the coefficient matrix. Remember indexing starts at zero
57 sys.SetA(0,0, 3.0); sys.SetA(0,1, -2.0); sys.SetA(0,2, -1.0);
58 sys.SetA(1,0, 2.0); sys.SetA(1,1, 4.0); sys.SetA(1,2, -2.0);
59 sys.SetA(2,0, 1.0); sys.SetA(2,1, 2.0); sys.SetA(2,2, 3.0);
60
61 // Set the right side
62 sys.SetB(0, -1.0);
63 sys.SetB(1, -4.0);
64 sys.SetB(2, 2.0);
65
66 // solve via Gauss elimination and backsubstitution
67 sys.SolveGauss();
68
69 // Get the solution
70 Console.WriteLine("Solution:");
71 Console.WriteLine(sys.Sol(0));
72 Console.WriteLine(sys.Sol(1));
73 Console.WriteLine(sys.Sol(2) + "\n");
74 Console.WriteLine("Error = " + sys.Check());
75 }
76 }

localhost:62027/8c379852-860d-4e98-a8e3-9ee3361b692c/ 2/2

You might also like