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

Calculus 1 Lab With Python

This document contains 3 math problems solved using Python. 1) It calculates expressions involving square roots, exponents, and logarithms. 2) Given variables x and y, it calculates square roots and fractions involving x and y. 3) Given two vectors a and b, it calculates their magnitudes, the distance between them, and uses laws of cosines and dot products to find the cosine of the angle between the vectors.

Uploaded by

Waleed Riaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views

Calculus 1 Lab With Python

This document contains 3 math problems solved using Python. 1) It calculates expressions involving square roots, exponents, and logarithms. 2) Given variables x and y, it calculates square roots and fractions involving x and y. 3) Given two vectors a and b, it calculates their magnitudes, the distance between them, and uses laws of cosines and dot products to find the cosine of the angle between the vectors.

Uploaded by

Waleed Riaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Use Python to solve each problem.

# Importing basic math module


import math

Question No. 01
Calculate the following:


3
80 5
1. 8+ +e
2.6
1

2. 23+45 3
+ln ( 589.006 )
16 ×0.7
# First Part
ans1 = math.sqrt(8+80/2.6)+math.exp(3/5)
print("The solution is", ans1)

The solution is 8.048613060343758

# Second Part
ans2 = (23+45**(1/3))/(16*0.7)+math.log(589.006)
print("The solution is", ans2)

The solution is 8.749587558257815

Question No. 02
Define the variable x=4.6 and y=1.7 , then calculate the following:

√ x + y +2 x 2 − x y 2
1. 2
(x− y)
2. √ x 2+ y 2. In print statement, state whether or not your answer is equal to x + y (which
you can check in your hear or by hand).
x = 4.6
y = 1.7

# First Part
ans3 = math.sqrt(x+y)/(x-y)**2 + 2*x**2 - x*y**2
print("The solution is", ans3)

The solution is 29.324451852509178

# Second Part
ans4 = math.sqrt(x**2+y**2)
ans5 = x+y
print("The solution to sqrt(x^2+y^2) which is ", ans4, "is not equal
to", ans5)

The solution to sqrt(x^2+y^2) which is 4.904079934095691 is not equal


to 6.3

Question No. 03
Let a and b be the vectors ⟨ 9.1 ,14.47 ⟩ and ⟨ −5.55 , 9.62 ⟩. (NOTE: for all calculations in this
problem, use the definitions from class rather than trying to look up built-in functions).
1. Compute |a ) and |b ).
2. Use the Law of Cosines to find the cosine of the angle C between the vectors: \
begin{align} \cos(C) & = \frac{|a|^2+|b|^2-c^2}{2|a| |b|} \end{align} where c is the
distance between the points corresponding to a and b above.
3. Use the dot product formula to find the cosine of the angle C between the vectors
and show it is equal to the answer for (b). \begin{align} \cos(C) & = \frac{a\cdot b}{|
a| |b|} \end{align}
# Vectors a and b
a = [9.1, 14.47]
b = [-5.55, 9.62]

# First Part
magnitude_a = math.sqrt(sum(x**2 for x in a))
print("The magnitude of vector a is", magnitude_a)

The magnitude of vector a is 17.093592366732043

magnitude_b = math.sqrt(sum(x**2 for x in b))


print("The magnitude of vector b is", magnitude_b)

The magnitude of vector b is 11.10616495465469

# Definining the distance function betweeen a and b


def dist(a1,a2):
x_dist = [a1[x]-a2[x] for x in range(len(a1))]
squared = [alpha**2 for alpha in x_dist]
result = math.sqrt(sum(squared))
return result

# Second Part
Cosine_Angle = (magnitude_a**2+magnitude_b**2-
(dist(a,b))**2)/(2*magnitude_a*magnitude_b)
print("The Cosine angle C between a and b is", Cosine_Angle)

The Cosine angle C between a and b is 0.4672061280056666

ans6 = sum([a[j]*b[j] for j in


range(len(b))])/(magnitude_a*magnitude_b)
print("The Cosine of the angle C between a and b is", ans6)
The Cosine of the angle C between a and b is 0.46720612800566663

You might also like