Lab 2 NA
Lab 2 NA
LIST OF TASKS
TASK NO OBJECTIVE
1 Write a Python program that calculates the absolute as well as relative error present in the
following measurements; Actual values: [11.0098, 167.902, 56.0567, 67.9860] Measured values:
[12.0001, 166.802, 55.0001, 69.0000]
2 Write a Python program the find the propagated error in the area and perimeter found for the
following measurements: - SQUARE (length : 45.09 cm ; uncertainty : 0.01 cm) - CIRCLE (radius :
34.90 cm ; uncertainty : 0.05 cm) - TRIANGLE (side1 : 70.9 m ; uncertainty : 0.23 m, side2 :
89.07cm ; uncertainty : 0.07 m, base : 76.07cm ; uncertainty : 0.04 m, height : 100.07cm ;
uncertainty : 0.05 m) - TRAPEZIUM(side1 : 670.9 m ; uncertainty : 0.53 m (parallel one), side2 :
849.07cm ; uncertainty : 0.27 m (parallel one) side3 : 376.07cm ; uncertainty : 0.74 m, side4 :
716.07cm ; uncertainty : 0.14 m, height : 231.07cm ; uncertainty : 0.25 m)
3 . Write a Python program that calculates the square root of following numbers using both the
math.sqrt function (which uses floating-point arithmetic) and a custom square root function
that uses integer arithmetic. Then, find and compare the results to observe the rounding error.
(56.90, 100.45, 67.90, 25.67, 56.67)
4
Write a python program which find the value of PI (π) using Taylor series, and then
find the truncating error occurred due to the use of finite number of terms. HINT:
arctan (1) = π/4, and formula for finding Tylor series for arctan is: 𝐚𝐫𝐜𝐭𝐚𝐧(𝐱) = ∑ (−1)
𝑛𝑧 2𝑛+1 2𝑛+1 ; ∞ 𝑛=0 |z| ≤ 1, z ≠ i, i
Submitted On:
Date: 16/10/23
Task No. 01:
Write a Python program that calculates the absolute as well as relative error present in the following measurements;
Actual values: [11.0098, 167.902, 56.0567, 67.9860] Measured values: [12.0001, 166.802, 55.0001, 69.0000]
Solution:
Solution:
import math
# Print results
print("Square:")
print(f"Area: {area_square} cm^2 (±{area_error_square} cm^2)")
print(f"Perimeter: {perimeter_square} cm (±{perimeter_error_square} cm)")
print()
print("Circle:")
print(f"Area: {area_circle} cm^2 (±{area_error_circle} cm^2)")
print(f"Perimeter: {perimeter_circle} cm (±{perimeter_error_circle} cm)")
print()
print("Triangle:")
print(f"Area: {area_triangle} cm^2 (±{area_error_triangle} cm^2)")
print(f"Perimeter: {perimeter_triangle} cm (±{perimeter_error_triangle} cm)")
print()
print("Trapezium:")
print(f"Area: {area_trapezium} cm^2 (±{area_error_trapezium} cm^2)")
print(f"Perimeter: {perimeter_trapezium} cm (±{perimeter_error_trapezium} cm)")
Output:
Solution:
Output:
Solution: