<jupyter_start><jupyter_text>Problem? solve this?:    $$ \frac{acc_{direction}}{\sin(\theta+\Delta\theta)} = \frac{acc_{reverse}}{\sin(\theta-\Delta\theta)}$$    - vi denne lighed hvor vi prøver at gøre delta theta så lille som mulight ved at difference nedenfor er mindre end (0.000001).- begge accelerationer, og theta er normalfordelinger med en sigma, mens deltatheta er ukendt.  Code as is (more or less)<jupyter_code>import numpy as np

r = np.random
r.seed(42)


#N_exp =1000
optimize_max_steps=1000
print_steps = optimize_max_steps/10

for iexp in range(N_exp):
    # Generate random experiment?
    a_norm = r.normal(1.5, 0.1)
    a_rev = r.normal(1.4, 0.1)
    # Why is theta different. 
    # isn't theta (the inclination of the table the same)
    # and we try to find a Delta theta that will align it better 
    # (ie. correct for the accellation difference)?
    theta_norm = r.normal(13.4, 0.2)
    theta_rev = r.normal(13.9,0.3)

    diff = 1.0
    # These are in radian ie. sin(3.14) = 0, sin(3.14/2 = 1)
    dtheta= 1
    ddtheta = 0.03
    N=0
    diff_new = 1
    while (diff_new > 1e-6):
        # calc both sides of equation
        norm = a_norm/np.sin(theta_norm+dtheta)
        rev = a_rev/np.sin(theta_rev-dtheta)
        # find diference
        diff_new = abs(norm-rev)
        # find ratio of difference compared to original distance
        # Quite unorthodox but seems to work :)
        ratio = diff_new/diff
        # subtract a smaller and smaller amount
        # Note since diff_abs is always positive you only subtract values from it
        # Since sinus is cyclical it works in this case but would not generalize
        dtheta -= ddtheta*ratio

        #diff = diff_new


        
        if iexp == 0 and N%print_steps == 0:
            print(f'Difference = {diff_new}, dtheta= {dtheta}, iteration = {N}')
        N += 1
        
        if N==optimize_max_steps:
            break
np.sin(np.pi/2)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup