0% found this document useful (0 votes)
8 views7 pages

Sagemath Practical PDF 3

The document outlines various vector operations using SageMath, including the computation of the Triple Scalar Product, Vector Projection, determination of coplanarity, finding the angle between two vectors, and calculating the intersection point of two 2D lines. Each section provides a clear aim, procedure, code snippets, and outputs for the respective calculations. The results demonstrate the application of vector mathematics in practical scenarios.

Uploaded by

nonewaste00
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)
8 views7 pages

Sagemath Practical PDF 3

The document outlines various vector operations using SageMath, including the computation of the Triple Scalar Product, Vector Projection, determination of coplanarity, finding the angle between two vectors, and calculating the intersection point of two 2D lines. Each section provides a clear aim, procedure, code snippets, and outputs for the respective calculations. The results demonstrate the application of vector mathematics in practical scenarios.

Uploaded by

nonewaste00
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/ 7

1.

Triple Scalar Product of Three Vectors

Aim: Compute the Triple Scalar Product of Three Vectors

Procedure:

Step 1: Define three 3D vectors.

Step 2: Calculate the cross product of the first two vectors.

Step 3: Compute the dot product of the cross product with the third vector.

Step 4: Display the result, which represents the volume of the parallelepiped formed by
the vectors.

Code:

Sage: v1 = vector([1, 2, 3])

Sage: v2 = vector([4, 5, 6])

Sage: v3 = vector([7, 8, 9])

Sage: cross_prod = v1.cross_product(v2)

Sage: triple_scalar_product = cross_prod.dot_product(v3)

Sage: print("The triple scalar product is:", triple_scalar_product)

Output:The triple scalar product is: 0

Result:

Hence, the got the solution for the given equation using SageMath.
2. Vector Projection of One Vector onto Another:

Aim: Find the Vector Projection of One Vector onto Another

Procedure:

Step 1: Define two vectors.

Step 2: Calculate the dot product of the vectors.

Step 3: Compute the magnitude squared of the second vector.

Step 4: Multiply the second vector by the scalar (dot_product / magnitude_squared).

Step 5: Display the projection vector.

Code:

Sage: v1 = vector([1, 2, 3])

Sage: v2 = vector([4, 5, 6])

Sage: projection = (v1.dot_product(v2) / v2.norm()^2) * v2

Sage: print("The projection of v1 onto v2 is:", projection)

Output:

The projection of v1 onto v2 is: (128/77, 160/77, 192/77)

Result:

Hence, the got the solution for the given equation using SageMath.
3. Three Vectors are Coplanar or not:

Aim: Determine if Three Vectors are Coplanar

Procedure:

Step 1: Define three 3D vectors.

Step 2: Calculate the triple scalar product using the cross product and dot product
methods.

Step 3: If the triple scalar product is 0, the vectors are coplanar.

Step 4: Display whether the vectors are coplanar or not.

Code:

Sage: v1 = vector([1, 2, 3])

Sage: v2 = vector([4, 5, 6])

Sage: v3 = vector([7, 8, 9])

Sage: triple_scalar_product = v1.cross_product(v2).dot_product(v3)

Sage: if triple_scalar_product == 0:

Sage: print("The vectors are coplanar.")

Sage: else:

Sage: print("The vectors are not coplanar.")

Output:

The vectors are coplanar.

Result:

Hence, the got the solution for the given equation using SageMath.
4. Angle Between Two Vectors

Aim: Finding the Angle Between Two Vectors

Procedure:

Step 1: Define two vectors.

Step 2: Calculate the dot product.

Step 3: Compute the magnitudes of both vectors.

Step 4: Use the formula cos(theta) = dot_product / (|v1| * |v2|).

Step 5: Calculate the angle using the arccos function.

Code:

Sage: from sage.all import *

Sage: import math

Sage: v1 = vector([1, 2, 3])

Sage: v2 = vector([4, 5, 6])

Sage: dot_product = v1.dot_product(v2)

Sage: magnitude_v1 = v1.norm()

Sage: magnitude_v2 = v2.norm()

Sage: cos_theta = dot_product / (magnitude_v1 * magnitude_v2)

Sage: angle_rad = arccos(cos_theta).n() # Convert to numerical value

Sage: angle_deg = (angle_rad * (180 / math.pi)).n() # Convert to degrees

Sage: print("The angle between the vectors is:", angle_deg, "degrees")

Output: The angle between the vectors is: 12.9331544918991 degrees

Result: Hence, the got the solution for the given equation using SageMath.
5. Point of Intersection of Two 2D Lines

Aim: Find the Point of Intersection of Two 2D Lines

Procedure:

Step 1: Represent the two lines in the form:

a1x+b1y=c1

a2x+b2y=c2

Step 2: Convert these equations into matrix form:

a1 a2 . x c1

b1 b2 y = c2

Step 3: Solve for (x,y)(x, y)(x,y) using the matrix inverse method.

Step 4: If the determinant of the coefficient matrix is zero, the lines are either parallel or
identical, meaning they have no unique intersection.

Step 5: Otherwise, compute and print the intersection point.

Code:

Sage: from sage.all import *

Sage: a1, b1, c1 = 2, -1, 4

Sage: a2, b2, c2 = 1, 1, 2

Sage: A = matrix(RR, [[a1, b1], [a2, b2]])

Sage: C = vector(RR, [c1, c2])

Sage: if A.det() != 0:

Sage: intersection = A.inverse() * C

Sage: print("The point of intersection is:", intersection)

Sage: else:

Sage: print("The lines are parallel or coincident, no unique intersection.")

Output: The point of intersection is: (2.0, 0.0)


Result:

Hence, the got the solution for the given equation using SageMath.

You might also like