From aa31ce258d7b7b6b5a82a753beac06d2f69f41e0 Mon Sep 17 00:00:00 2001 From: deadvey Date: Sat, 6 Dec 2025 20:10:21 +0000 Subject: [PATCH] Added electric field calculations and corrected a bug in the fringe spacing function --- docs/mathgenerator/_gen_list.html | 6 +- docs/mathgenerator/computer_science.html | 1218 ++++++++++++---------- docs/mathgenerator/physics.html | 383 +++++-- docs/mathgenerator/statistics.html | 40 +- docs/search.js | 2 +- mathgenerator/_gen_list.py | 2 + mathgenerator/computer_science.py | 28 + mathgenerator/physics.py | 62 +- mathgenerator/statistics.py | 22 +- 9 files changed, 1096 insertions(+), 667 deletions(-) diff --git a/docs/mathgenerator/_gen_list.html b/docs/mathgenerator/_gen_list.html index 829750c..5fe8783 100644 --- a/docs/mathgenerator/_gen_list.html +++ b/docs/mathgenerator/_gen_list.html @@ -216,7 +216,9 @@ 138 ("resistivity", "physics"), 139 ("fringe_spacing", "physics"), 140 ("lba_to_chs", "computer_science"), -141] +141 ("floating_point_binary_to_decimal", "computer_science"), +142 ("electric_field_strength_two_points", "physics"), +143] @@ -225,7 +227,7 @@
gen_list = - [('addition', 'basic_math'), ('subtraction', 'basic_math'), ('multiplication', 'basic_math'), ('division', 'basic_math'), ('binary_complement_1s', 'computer_science'), ('modulo_division', 'computer_science'), ('square_root', 'basic_math'), ('power_rule_differentiation', 'calculus'), ('square', 'basic_math'), ('lcm', 'misc'), ('DELETED', 'DELETED'), ('basic_algebra', 'algebra'), ('log', 'algebra'), ('fraction_to_decimal', 'basic_math'), ('decimal_to_binary', 'computer_science'), ('binary_to_decimal', 'computer_science'), ('divide_fractions', 'basic_math'), ('multiply_int_to_22_matrix', 'algebra'), ('area_of_triangle', 'geometry'), ('valid_triangle', 'geometry'), ('midpoint_of_two_points', 'algebra'), ('factoring', 'algebra'), ('third_angle_of_triangle', 'geometry'), ('system_of_equations', 'algebra'), ('distance_two_points', 'algebra'), ('pythagorean_theorem', 'geometry'), ('linear_equations', 'algebra'), ('prime_factors', 'misc'), ('fraction_multiplication', 'basic_math'), ('angle_regular_polygon', 'geometry'), ('combinations', 'statistics'), ('factorial', 'basic_math'), ('surface_area_cube', 'geometry'), ('surface_area_cuboid', 'geometry'), ('surface_area_cylinder', 'geometry'), ('volume_cube', 'geometry'), ('volume_cuboid', 'geometry'), ('volume_cylinder', 'geometry'), ('surface_area_cone', 'geometry'), ('volume_cone', 'geometry'), ('common_factors', 'misc'), ('intersection_of_two_lines', 'algebra'), ('permutation', 'statistics'), ('vector_cross', 'algebra'), ('compare_fractions', 'basic_math'), ('simple_interest', 'algebra'), ('matrix_multiplication', 'algebra'), ('cube_root', 'basic_math'), ('power_rule_integration', 'calculus'), ('fourth_angle_of_quadrilateral', 'geometry'), ('quadratic_equation', 'algebra'), ('DELETED', 'DELETED'), ('dice_sum_probability', 'statistics'), ('exponentiation', 'basic_math'), ('confidence_interval', 'statistics'), ('surds_comparison', 'misc'), ('fibonacci_series', 'computer_science'), ('basic_trigonometry', 'geometry'), ('sum_of_polygon_angles', 'geometry'), ('data_summary', 'statistics'), ('surface_area_sphere', 'geometry'), ('volume_sphere', 'geometry'), ('nth_fibonacci_number', 'computer_science'), ('profit_loss_percent', 'misc'), ('binary_to_hex', 'computer_science'), ('multiply_complex_numbers', 'algebra'), ('geometric_progression', 'misc'), ('geometric_mean', 'misc'), ('harmonic_mean', 'misc'), ('euclidian_norm', 'misc'), ('angle_btw_vectors', 'geometry'), ('absolute_difference', 'basic_math'), ('vector_dot', 'algebra'), ('binary_2s_complement', 'computer_science'), ('invert_matrix', 'algebra'), ('sector_area', 'geometry'), ('mean_median', 'statistics'), ('int_matrix_22_determinant', 'algebra'), ('compound_interest', 'algebra'), ('decimal_to_hexadeci', 'computer_science'), ('percentage', 'basic_math'), ('celsius_to_fahrenheit', 'misc'), ('arithmetic_progression_term', 'misc'), ('arithmetic_progression_sum', 'misc'), ('decimal_to_octal', 'computer_science'), ('decimal_to_roman_numerals', 'misc'), ('degree_to_rad', 'geometry'), ('radian_to_deg', 'geometry'), ('trig_differentiation', 'calculus'), ('definite_integral', 'calculus'), ('is_prime', 'basic_math'), ('bcd_to_decimal', 'computer_science'), ('complex_to_polar', 'misc'), ('set_operation', 'misc'), ('base_conversion', 'misc'), ('curved_surface_area_cylinder', 'geometry'), ('perimeter_of_polygons', 'geometry'), ('power_of_powers', 'basic_math'), ('quotient_of_power_same_base', 'misc'), ('quotient_of_power_same_power', 'misc'), ('complex_quadratic', 'algebra'), ('is_leap_year', 'misc'), ('minutes_to_hours', 'misc'), ('decimal_to_bcd', 'computer_science'), ('circumference', 'geometry'), ('combine_like_terms', 'algebra'), ('signum_function', 'misc'), ('conditional_probability', 'statistics'), ('arc_length', 'geometry'), ('binomial_distribution', 'misc'), ('stationary_points', 'calculus'), ('expanding', 'algebra'), ('area_of_circle', 'geometry'), ('volume_cone_frustum', 'geometry'), ('equation_of_line_from_two_points', 'geometry'), ('area_of_circle_given_center_and_point', 'geometry'), ('factors', 'misc'), ('volume_hemisphere', 'geometry'), ('percentage_difference', 'basic_math'), ('percentage_error', 'basic_math'), ('greatest_common_divisor', 'basic_math'), ('product_of_scientific_notations', 'misc'), ('volume_pyramid', 'geometry'), ('surface_area_pyramid', 'geometry'), ('is_composite', 'basic_math'), ('complementary_and_supplementary_angle', 'geometry'), ('simplify_square_root', 'basic_math'), ('line_equation_from_2_points', 'algebra'), ('orthogonal_projection', 'algebra'), ('area_of_trapezoid', 'geometry'), ('tribonacci_series', 'computer_science'), ('nth_tribonacci_number', 'computer_science'), ('velocity_of_object', 'misc'), ('binary_addition', 'computer_science'), ('kinetic_energy', 'physics'), ('potential_dividers', 'physics'), ('resistivity', 'physics'), ('fringe_spacing', 'physics'), ('lba_to_chs', 'computer_science')] + [('addition', 'basic_math'), ('subtraction', 'basic_math'), ('multiplication', 'basic_math'), ('division', 'basic_math'), ('binary_complement_1s', 'computer_science'), ('modulo_division', 'computer_science'), ('square_root', 'basic_math'), ('power_rule_differentiation', 'calculus'), ('square', 'basic_math'), ('lcm', 'misc'), ('DELETED', 'DELETED'), ('basic_algebra', 'algebra'), ('log', 'algebra'), ('fraction_to_decimal', 'basic_math'), ('decimal_to_binary', 'computer_science'), ('binary_to_decimal', 'computer_science'), ('divide_fractions', 'basic_math'), ('multiply_int_to_22_matrix', 'algebra'), ('area_of_triangle', 'geometry'), ('valid_triangle', 'geometry'), ('midpoint_of_two_points', 'algebra'), ('factoring', 'algebra'), ('third_angle_of_triangle', 'geometry'), ('system_of_equations', 'algebra'), ('distance_two_points', 'algebra'), ('pythagorean_theorem', 'geometry'), ('linear_equations', 'algebra'), ('prime_factors', 'misc'), ('fraction_multiplication', 'basic_math'), ('angle_regular_polygon', 'geometry'), ('combinations', 'statistics'), ('factorial', 'basic_math'), ('surface_area_cube', 'geometry'), ('surface_area_cuboid', 'geometry'), ('surface_area_cylinder', 'geometry'), ('volume_cube', 'geometry'), ('volume_cuboid', 'geometry'), ('volume_cylinder', 'geometry'), ('surface_area_cone', 'geometry'), ('volume_cone', 'geometry'), ('common_factors', 'misc'), ('intersection_of_two_lines', 'algebra'), ('permutation', 'statistics'), ('vector_cross', 'algebra'), ('compare_fractions', 'basic_math'), ('simple_interest', 'algebra'), ('matrix_multiplication', 'algebra'), ('cube_root', 'basic_math'), ('power_rule_integration', 'calculus'), ('fourth_angle_of_quadrilateral', 'geometry'), ('quadratic_equation', 'algebra'), ('DELETED', 'DELETED'), ('dice_sum_probability', 'statistics'), ('exponentiation', 'basic_math'), ('confidence_interval', 'statistics'), ('surds_comparison', 'misc'), ('fibonacci_series', 'computer_science'), ('basic_trigonometry', 'geometry'), ('sum_of_polygon_angles', 'geometry'), ('data_summary', 'statistics'), ('surface_area_sphere', 'geometry'), ('volume_sphere', 'geometry'), ('nth_fibonacci_number', 'computer_science'), ('profit_loss_percent', 'misc'), ('binary_to_hex', 'computer_science'), ('multiply_complex_numbers', 'algebra'), ('geometric_progression', 'misc'), ('geometric_mean', 'misc'), ('harmonic_mean', 'misc'), ('euclidian_norm', 'misc'), ('angle_btw_vectors', 'geometry'), ('absolute_difference', 'basic_math'), ('vector_dot', 'algebra'), ('binary_2s_complement', 'computer_science'), ('invert_matrix', 'algebra'), ('sector_area', 'geometry'), ('mean_median', 'statistics'), ('int_matrix_22_determinant', 'algebra'), ('compound_interest', 'algebra'), ('decimal_to_hexadeci', 'computer_science'), ('percentage', 'basic_math'), ('celsius_to_fahrenheit', 'misc'), ('arithmetic_progression_term', 'misc'), ('arithmetic_progression_sum', 'misc'), ('decimal_to_octal', 'computer_science'), ('decimal_to_roman_numerals', 'misc'), ('degree_to_rad', 'geometry'), ('radian_to_deg', 'geometry'), ('trig_differentiation', 'calculus'), ('definite_integral', 'calculus'), ('is_prime', 'basic_math'), ('bcd_to_decimal', 'computer_science'), ('complex_to_polar', 'misc'), ('set_operation', 'misc'), ('base_conversion', 'misc'), ('curved_surface_area_cylinder', 'geometry'), ('perimeter_of_polygons', 'geometry'), ('power_of_powers', 'basic_math'), ('quotient_of_power_same_base', 'misc'), ('quotient_of_power_same_power', 'misc'), ('complex_quadratic', 'algebra'), ('is_leap_year', 'misc'), ('minutes_to_hours', 'misc'), ('decimal_to_bcd', 'computer_science'), ('circumference', 'geometry'), ('combine_like_terms', 'algebra'), ('signum_function', 'misc'), ('conditional_probability', 'statistics'), ('arc_length', 'geometry'), ('binomial_distribution', 'misc'), ('stationary_points', 'calculus'), ('expanding', 'algebra'), ('area_of_circle', 'geometry'), ('volume_cone_frustum', 'geometry'), ('equation_of_line_from_two_points', 'geometry'), ('area_of_circle_given_center_and_point', 'geometry'), ('factors', 'misc'), ('volume_hemisphere', 'geometry'), ('percentage_difference', 'basic_math'), ('percentage_error', 'basic_math'), ('greatest_common_divisor', 'basic_math'), ('product_of_scientific_notations', 'misc'), ('volume_pyramid', 'geometry'), ('surface_area_pyramid', 'geometry'), ('is_composite', 'basic_math'), ('complementary_and_supplementary_angle', 'geometry'), ('simplify_square_root', 'basic_math'), ('line_equation_from_2_points', 'algebra'), ('orthogonal_projection', 'algebra'), ('area_of_trapezoid', 'geometry'), ('tribonacci_series', 'computer_science'), ('nth_tribonacci_number', 'computer_science'), ('velocity_of_object', 'misc'), ('binary_addition', 'computer_science'), ('kinetic_energy', 'physics'), ('potential_dividers', 'physics'), ('resistivity', 'physics'), ('fringe_spacing', 'physics'), ('lba_to_chs', 'computer_science'), ('floating_point_binary_to_decimal', 'computer_science'), ('electric_field_strength_two_points', 'physics')]
diff --git a/docs/mathgenerator/computer_science.html b/docs/mathgenerator/computer_science.html index 6c1254a..53e00e5 100644 --- a/docs/mathgenerator/computer_science.html +++ b/docs/mathgenerator/computer_science.html @@ -52,6 +52,9 @@

API Documentation

@@ -85,88 +91,147 @@ -
 1import random
- 2import math
- 3
- 4# Generic
- 5def kinetic_energy(max_mass=1000, max_vel=100):
- 6   r"""Kinetic Energy calculation using Ek = 0.5 * m * v^2
- 7
- 8    | Ex. Problem | Ex. Solution |
- 9    | --- | --- |
-10    | What is the kinetic energy of an object of mass $5 kg$ and velocity $10 m/s$ | $250 J$ |
-11    """
-12   velocity = round(random.uniform(1, max_vel),2)
-13   mass = round(random.uniform(1, max_mass),2)
-14   kinetic_energy = round((0.5 * mass * velocity**2), 2)
-15
-16
-17   problem = f"What is the kinetic energy of an object of mass ${mass} kg$ and velocity ${velocity} m/s$?"
-18   solution = f'${kinetic_energy} J$'
-19   return problem, solution
-20
-21
-22# Electricity
-23def potential_dividers(max_vin=50, max_resistance=500):
-24   r"""Potential Divider question using Vout = (Vin * R2) / (R2 + R1)
-25
-26    | Ex. Problem | Ex. Solution |
-27    | --- | --- |
-28    | In a Potential Divider, if resistors R1 and R2 have resistances of $100 \Omega$ and $50 \Omega$ respectively, and the cell has $12 V$ What is the output potential difference across R2? | $4 V$ |
-29    """
-30   '''
-31    This is what a potential divider circuit looks like:
-32    ------
-33    |    R1
-34 Vi =    |----o
-35    |    R2      Vout
-36    |____|____o
-37    '''
-38   vin = random.randint(0, max_vin)          # Voltage input of cell
-39   r1 = random.randint(0, max_resistance)    # Resistance of R1
-40   r2 = random.randint(0, max_resistance)    # Resistance of R2
-41   vout = round((vin * r2) / (r1 + r2),2)    # Voltage output across R2
-42
-43   problem = f"In a Potential Divider, if resistors R1 and R2 have resistances of ${r1} \\Omega$ and ${r2} \\Omega$ respectively, and the cell has ${vin} V$ What is the output potential difference across R2?"
-44   solution = f"${vout} V$"
-45   return problem, solution
-46
-47def resistivity(max_diameter_mm=5, max_length_cm=100, max_resistance=0.1):
-48   r"""Calculate the Resistivity using the equation R = (pL)/A, where R = Resistance, L = length of wire, p = resistivity and A = cross sectional area of wire
-49
-50    | Ex. Problem | Ex. Solution |
-51    | --- | --- |
-52    | A wire has resistance $30 m\Omega$ when it is $83.64 cm$ long with a diameter of $4.67 mm$. Calculate the resistivity of the wire | $6.14e-07 \Omega m$ |
-53    """
-54   # This question requires a lot of unit conversions and calculating the area of a circle from diameter
-55   diameter_mm = round(random.uniform(0, max_diameter_mm),2)   # Random diameter in mm
-56   cross_sectional_area = math.pi * (diameter_mm / 2000)**2    # Calculate the cross sectional area using pi r²
-57   length_cm = round(random.uniform(0, max_length_cm),2)       # Random wire length in cm
-58   resistance = round(random.uniform(0, max_resistance),2)     # Random reistance in ohms
-59
-60   resistivity = (resistance * cross_sectional_area) / (length_cm / 100)
-61
-62   problem = f"A wire has resistance ${resistance*1000} m\\Omega$ when it is ${length_cm} cm$ long with a diameter of ${diameter_mm} mm$. Calculate the resistivity of the wire"
-63   solution = f"${resistivity:.2e} \\Omega m$"
-64
-65   return problem, solution
-66
-67# Waves
-68def fringe_spacing(max_screen_distance=30, max_slit_spacing_mm=100):
-69   r"""Calculate the fringe spacing in a double slit experiment with w=(λD)/s
-70    | Ex. Problem | Ex. Solution |
-71    | --- | --- |
-72    | A laser with a wavelength of $450nm$ is shone through a double slit system to produce an interference pattern on a screen.  The screen is $12m$ from the slits and the slits are $0.30mm$ apart. Calculate the spacing between the bright fringes. | Using the equation $\\frac{{\\lambda D}}{{s}}$, we get a fringe spacing of $0.018m$ |
-73    """
-74   wavelength_nm = random.randint(380,750)      # Random wavelength between violet and red (nm)
-75   screen_distance = random.randint(0, max_screen_distance)    # Random distance between screen and slits (m)
-76   slit_spacing_mm = random.randint(0, max_slit_spacing_mm)    # Random slit spacing (mm)
-77
-78   fringe_spacing = round((((wavelength_nm * 10**-9) * screen_distance) / (slit_spacing_mm * 10**-3)),5)
-79
-80   problem = f"A laser with a wavelength of ${wavelength_nm}nm$ is shone through a double slit system to produce an interference pattern on a screen.  The screen is ${screen_distance}m$ from the slits and the slits are ${slit_spacing_mm}mm$ apart. Calculate the spacing between the bright fringes."
-81   solution = f"Using the equation $\\frac{{\\lambda D}}{{s}}$, we get a fringe spacing of ${fringe_spacing}m$"
-82   return problem, solution
+                        
  1import random
+  2import math
+  3
+  4# Mechanics
+  5def kinetic_energy(max_mass=1000, max_vel=100):
+  6   r"""Kinetic Energy calculation using Ek = 0.5 * m * v^2
+  7
+  8    | Ex. Problem | Ex. Solution |
+  9    | --- | --- |
+ 10    | What is the kinetic energy of an object of mass $5 kg$ and velocity $10 m/s$ | $250 J$ |
+ 11    """
+ 12   velocity = round(random.uniform(1, max_vel),2)
+ 13   mass = round(random.uniform(1, max_mass),2)
+ 14   kinetic_energy = round((0.5 * mass * velocity**2), 2)
+ 15
+ 16
+ 17   problem = f"What is the kinetic energy of an object of mass ${mass} kg$ and velocity ${velocity} m/s$?"
+ 18   solution = f'${kinetic_energy} J$'
+ 19   return problem, solution
+ 20
+ 21
+ 22# Electricity & Electric Fields
+ 23def potential_dividers(max_vin=50, max_resistance=500):
+ 24   r"""Potential Divider question using Vout = (Vin * R2) / (R2 + R1)
+ 25
+ 26    | Ex. Problem | Ex. Solution |
+ 27    | --- | --- |
+ 28    | In a Potential Divider, if resistors R1 and R2 have resistances of $100 \Omega$ and $50 \Omega$ respectively, and the cell has $12 V$ What is the output potential difference across R2? | $4 V$ |
+ 29    """
+ 30   '''
+ 31    This is what a potential divider circuit looks like:
+ 32    ------
+ 33    |    R1
+ 34 Vi =    |----o
+ 35    |    R2      Vout
+ 36    |____|____o
+ 37    '''
+ 38   vin = random.randint(0, max_vin)          # Voltage input of cell
+ 39   r1 = random.randint(0, max_resistance)    # Resistance of R1
+ 40   r2 = random.randint(0, max_resistance)    # Resistance of R2
+ 41   vout = round((vin * r2) / (r1 + r2),2)    # Voltage output across R2
+ 42
+ 43   problem = f"In a Potential Divider, if resistors R1 and R2 have resistances of ${r1} \\Omega$ and ${r2} \\Omega$ respectively, and the cell has ${vin} V$ What is the output potential difference across R2?"
+ 44   solution = f"${vout} V$"
+ 45   return problem, solution
+ 46
+ 47def resistivity(max_diameter_mm=5, max_length_cm=100, max_resistance=0.1):
+ 48   r"""Calculate the Resistivity using the equation R = (pL)/A, where R = Resistance, L = length of wire, p = resistivity and A = cross sectional area of wire
+ 49
+ 50    | Ex. Problem | Ex. Solution |
+ 51    | --- | --- |
+ 52    | A wire has resistance $30 m\Omega$ when it is $83.64 cm$ long with a diameter of $4.67 mm$. Calculate the resistivity of the wire | $6.14e-07 \Omega m$ |
+ 53    """
+ 54   # This question requires a lot of unit conversions and calculating the area of a circle from diameter
+ 55   diameter_mm = round(random.uniform(0, max_diameter_mm),2)   # Random diameter in mm
+ 56   cross_sectional_area = math.pi * (diameter_mm / 2000)**2    # Calculate the cross sectional area using pi r²
+ 57   length_cm = round(random.uniform(0, max_length_cm),2)       # Random wire length in cm
+ 58   resistance = round(random.uniform(0, max_resistance),2)     # Random reistance in ohms
+ 59
+ 60   resistivity = (resistance * cross_sectional_area) / (length_cm / 100)
+ 61
+ 62   problem = f"A wire has resistance ${resistance*1000} m\\Omega$ when it is ${length_cm} cm$ long with a diameter of ${diameter_mm} mm$. Calculate the resistivity of the wire"
+ 63   solution = f"${resistivity:.2e} \\Omega m$"
+ 64
+ 65   return problem, solution
+ 66
+ 67def electric_field_strength_two_points(max_seperation_cm=100, max_charge_uC=1000):
+ 68    r"""Calculate the total electric field strength at point P with given points A and B, using the equation kQ/r²
+ 69
+ 70    | Ex. Problem | Ex. Solution |
+ 71    | --- | --- |
+ 72    | Charges A and B and point P are arranged like this: B <-- 7 cm --> P <-- 79 cm --> A, Where A and B have charges of -56 µC and -410 µC, What is the electric field strength at point P? | $-751417824 NC^{-1}$ (to the right) |
+ 73
+ 74    """
+ 75    a_charge = random.randint(-max_charge_uC,max_charge_uC)
+ 76    b_charge = random.randint(-max_charge_uC,max_charge_uC)
+ 77    arrangement = [['P'],['A',a_charge],['B',b_charge]] # Arrangement of charge A, B and the point of focus
+ 78    random.shuffle(arrangement)
+ 79    seperations = [random.randint(0,max_seperation_cm), random.randint(0,max_seperation_cm)]
+ 80    total_efs = 0
+ 81    # Work out how far A and B are from P (vector)
+ 82    if arrangement[0][0] == 'P':
+ 83        arrangement[1].append(seperations[0])
+ 84        arrangement[2].append(seperations[0]+seperations[1])
+ 85    elif arrangement[1][0] == 'P':
+ 86        arrangement[0].append(-seperations[0])
+ 87        arrangement[2].append(seperations[1])
+ 88    else:
+ 89        arrangement[0].append(-(seperations[0]+seperations[1]))
+ 90        arrangement[1].append(-seperations[1])
+ 91
+ 92    # Work out the EFS at point P caused by A and B seperatley, then sum them together in `total_efs`
+ 93    for point in arrangement:
+ 94        if point[0] == 'P':
+ 95            continue
+ 96        else:
+ 97            efs = ((8.99*10**9)*(point[1]*10**-6))/((point[2]/100)**2) # efs = kQ/r²
+ 98            if point[2] > 0: efs = -efs
+ 99            point.append(efs)
+100            total_efs += efs
+101
+102    problem = f"Charges A and B and point P are arranged like this:\n{arrangement[0][0]} <-- ${seperations[0]}$ cm --> {arrangement[1][0]} <-- ${seperations[1]}$ cm --> {arrangement[2][0]}\nWhere A and B have charges of ${a_charge}$ µC and ${b_charge}$ µC\nWhat is the electric field strength at point P?"
+103    solution = f"${round(total_efs)} NC^{-1}$ (to the right)"
+104    return problem, solution
+105
+106
+107# Waves
+108def fringe_spacing(max_screen_distance=30, max_slit_spacing_mm=100):
+109   r"""Calculate the fringe spacing in a double slit experiment with w=(λD)/s
+110    | Ex. Problem | Ex. Solution |
+111    | --- | --- |
+112    | A laser with a wavelength of $450nm$ is shone through a double slit system to produce an interference pattern on a screen.  The screen is $12m$ from the slits and the slits are $0.30mm$ apart. Calculate the spacing between the bright fringes. | Using the equation $\\frac{{\\lambda D}}{{s}}$, we get a fringe spacing of $0.018m$ |
+113    """
+114   wavelength_nm = random.randint(380,750)      # Random wavelength between violet and red (nm)
+115   screen_distance = random.randint(0, max_screen_distance)    # Random distance between screen and slits (m)
+116   slit_spacing_mm = random.randint(0, max_slit_spacing_mm)    # Random slit spacing (mm)
+117
+118   fringe_spacing = round((((wavelength_nm * 10**-9) * screen_distance) / (slit_spacing_mm * 10**-3)),5)
+119
+120   problem = f"A laser with a wavelength of ${wavelength_nm}nm$ is shone through a double slit system to produce an interference pattern on a screen.  The screen is ${screen_distance}m$ from the slits and the slits are ${slit_spacing_mm}mm$ apart. Calculate the spacing between the bright fringes."
+121   solution = f"Using the equation $\\frac{{\\lambda D}}{{s}}$, we get a fringe spacing of ${fringe_spacing}m$"
+122   return problem, solution
+123
+124def diffraction_grating_wavelength(min_slits_per_mm=100, max_slits_per_mm=500, max_order_number=5):
+125    r"""Calculate the wavelength when given the number of slits per mm, order number and angle of order using the equation nλ = dsinθ
+126
+127    | Ex. Problem | Ex. Solution |
+128    | --- | --- |
+129    | A laser is shone through a diffraction grating which has $293$ lines per mm, the fringe of order number $2$ is at an angle of $0.39$ rad. Calculate the wavelength of the light | $\lambda = 6.487856913364529e-07m = 649nm |
+130
+131    """
+132    slits_per_mm = random.randint(min_slits_per_mm, max_slits_per_mm)
+133    slit_spacing = 1/(slits_per_mm * 1000)
+134    order_number = random.randint(1, max_order_number)
+135    angle_of_order = round(random.uniform(0.2, (math.pi/2)-0.2),2)
+136    wavelength = ((slit_spacing * math.sin(angle_of_order)) / order_number)
+137
+138    problem = f"A laser is shone through a diffraction grating which has ${slits_per_mm}$ lines per mm, the fringe of order number ${order_number}$ is at an angle of ${angle_of_order}$ rad. Calculate the wavelength of the light"
+139    solution = f"$\\lambda = {wavelength}m = {round(wavelength / 10**-9)}nm$"
+140
+141    return problem, solution
 
@@ -329,6 +394,78 @@
+ +
+ +
+ + def + electric_field_strength_two_points(max_seperation_cm=100, max_charge_uC=1000): + + + +
+ +
 68def electric_field_strength_two_points(max_seperation_cm=100, max_charge_uC=1000):
+ 69    r"""Calculate the total electric field strength at point P with given points A and B, using the equation kQ/r²
+ 70
+ 71    | Ex. Problem | Ex. Solution |
+ 72    | --- | --- |
+ 73    | Charges A and B and point P are arranged like this: B <-- 7 cm --> P <-- 79 cm --> A, Where A and B have charges of -56 µC and -410 µC, What is the electric field strength at point P? | $-751417824 NC^{-1}$ (to the right) |
+ 74
+ 75    """
+ 76    a_charge = random.randint(-max_charge_uC,max_charge_uC)
+ 77    b_charge = random.randint(-max_charge_uC,max_charge_uC)
+ 78    arrangement = [['P'],['A',a_charge],['B',b_charge]] # Arrangement of charge A, B and the point of focus
+ 79    random.shuffle(arrangement)
+ 80    seperations = [random.randint(0,max_seperation_cm), random.randint(0,max_seperation_cm)]
+ 81    total_efs = 0
+ 82    # Work out how far A and B are from P (vector)
+ 83    if arrangement[0][0] == 'P':
+ 84        arrangement[1].append(seperations[0])
+ 85        arrangement[2].append(seperations[0]+seperations[1])
+ 86    elif arrangement[1][0] == 'P':
+ 87        arrangement[0].append(-seperations[0])
+ 88        arrangement[2].append(seperations[1])
+ 89    else:
+ 90        arrangement[0].append(-(seperations[0]+seperations[1]))
+ 91        arrangement[1].append(-seperations[1])
+ 92
+ 93    # Work out the EFS at point P caused by A and B seperatley, then sum them together in `total_efs`
+ 94    for point in arrangement:
+ 95        if point[0] == 'P':
+ 96            continue
+ 97        else:
+ 98            efs = ((8.99*10**9)*(point[1]*10**-6))/((point[2]/100)**2) # efs = kQ/r²
+ 99            if point[2] > 0: efs = -efs
+100            point.append(efs)
+101            total_efs += efs
+102
+103    problem = f"Charges A and B and point P are arranged like this:\n{arrangement[0][0]} <-- ${seperations[0]}$ cm --> {arrangement[1][0]} <-- ${seperations[1]}$ cm --> {arrangement[2][0]}\nWhere A and B have charges of ${a_charge}$ µC and ${b_charge}$ µC\nWhat is the electric field strength at point P?"
+104    solution = f"${round(total_efs)} NC^{-1}$ (to the right)"
+105    return problem, solution
+
+ + +

Calculate the total electric field strength at point P with given points A and B, using the equation kQ/r²

+ + + + + + + + + + + + + + +
Ex. ProblemEx. Solution
Charges A and B and point P are arranged like this: B <-- 7 cm --> P <-- 79 cm --> A, Where A and B have charges of -56 µC and -410 µC, What is the electric field strength at point P?$-751417824 NC^{-1}$ (to the right)
+
+ +
@@ -341,21 +478,21 @@ -
69def fringe_spacing(max_screen_distance=30, max_slit_spacing_mm=100):
-70   r"""Calculate the fringe spacing in a double slit experiment with w=(λD)/s
-71    | Ex. Problem | Ex. Solution |
-72    | --- | --- |
-73    | A laser with a wavelength of $450nm$ is shone through a double slit system to produce an interference pattern on a screen.  The screen is $12m$ from the slits and the slits are $0.30mm$ apart. Calculate the spacing between the bright fringes. | Using the equation $\\frac{{\\lambda D}}{{s}}$, we get a fringe spacing of $0.018m$ |
-74    """
-75   wavelength_nm = random.randint(380,750)      # Random wavelength between violet and red (nm)
-76   screen_distance = random.randint(0, max_screen_distance)    # Random distance between screen and slits (m)
-77   slit_spacing_mm = random.randint(0, max_slit_spacing_mm)    # Random slit spacing (mm)
-78
-79   fringe_spacing = round((((wavelength_nm * 10**-9) * screen_distance) / (slit_spacing_mm * 10**-3)),5)
-80
-81   problem = f"A laser with a wavelength of ${wavelength_nm}nm$ is shone through a double slit system to produce an interference pattern on a screen.  The screen is ${screen_distance}m$ from the slits and the slits are ${slit_spacing_mm}mm$ apart. Calculate the spacing between the bright fringes."
-82   solution = f"Using the equation $\\frac{{\\lambda D}}{{s}}$, we get a fringe spacing of ${fringe_spacing}m$"
-83   return problem, solution
+            
109def fringe_spacing(max_screen_distance=30, max_slit_spacing_mm=100):
+110   r"""Calculate the fringe spacing in a double slit experiment with w=(λD)/s
+111    | Ex. Problem | Ex. Solution |
+112    | --- | --- |
+113    | A laser with a wavelength of $450nm$ is shone through a double slit system to produce an interference pattern on a screen.  The screen is $12m$ from the slits and the slits are $0.30mm$ apart. Calculate the spacing between the bright fringes. | Using the equation $\\frac{{\\lambda D}}{{s}}$, we get a fringe spacing of $0.018m$ |
+114    """
+115   wavelength_nm = random.randint(380,750)      # Random wavelength between violet and red (nm)
+116   screen_distance = random.randint(0, max_screen_distance)    # Random distance between screen and slits (m)
+117   slit_spacing_mm = random.randint(0, max_slit_spacing_mm)    # Random slit spacing (mm)
+118
+119   fringe_spacing = round((((wavelength_nm * 10**-9) * screen_distance) / (slit_spacing_mm * 10**-3)),5)
+120
+121   problem = f"A laser with a wavelength of ${wavelength_nm}nm$ is shone through a double slit system to produce an interference pattern on a screen.  The screen is ${screen_distance}m$ from the slits and the slits are ${slit_spacing_mm}mm$ apart. Calculate the spacing between the bright fringes."
+122   solution = f"Using the equation $\\frac{{\\lambda D}}{{s}}$, we get a fringe spacing of ${fringe_spacing}m$"
+123   return problem, solution
 
@@ -378,6 +515,58 @@
+
+
+ +
+ + def + diffraction_grating_wavelength(min_slits_per_mm=100, max_slits_per_mm=500, max_order_number=5): + + + +
+ +
125def diffraction_grating_wavelength(min_slits_per_mm=100, max_slits_per_mm=500, max_order_number=5):
+126    r"""Calculate the wavelength when given the number of slits per mm, order number and angle of order using the equation nλ = dsinθ
+127
+128    | Ex. Problem | Ex. Solution |
+129    | --- | --- |
+130    | A laser is shone through a diffraction grating which has $293$ lines per mm, the fringe of order number $2$ is at an angle of $0.39$ rad. Calculate the wavelength of the light | $\lambda = 6.487856913364529e-07m = 649nm |
+131
+132    """
+133    slits_per_mm = random.randint(min_slits_per_mm, max_slits_per_mm)
+134    slit_spacing = 1/(slits_per_mm * 1000)
+135    order_number = random.randint(1, max_order_number)
+136    angle_of_order = round(random.uniform(0.2, (math.pi/2)-0.2),2)
+137    wavelength = ((slit_spacing * math.sin(angle_of_order)) / order_number)
+138
+139    problem = f"A laser is shone through a diffraction grating which has ${slits_per_mm}$ lines per mm, the fringe of order number ${order_number}$ is at an angle of ${angle_of_order}$ rad. Calculate the wavelength of the light"
+140    solution = f"$\\lambda = {wavelength}m = {round(wavelength / 10**-9)}nm$"
+141
+142    return problem, solution
+
+ + +

Calculate the wavelength when given the number of slits per mm, order number and angle of order using the equation nλ = dsinθ

+ + + + + + + + + + + + + + +
Ex. ProblemEx. Solution
A laser is shone through a diffraction grating which has $293$ lines per mm, the fringe of order number $2$ is at an angle of $0.39$ rad. Calculate the wavelength of the light$\lambda = 6.487856913364529e-07m = 649nm
+
+ +