# C2 - W1 Lab Assignment

How can I get help with this assignment. I’ve been stuck on this for a while and can’t seem to find any documentation that will help me.

# This is why it is better to take N = 1001, not N = 1000

N = 1001
omega_array = np.linspace(0, 1, N, endpoint=True)

# This is organised as a function only for grading purposes.

def L_of_omega_array(omega_array, pA, pB):
N = len(omega_array)
L_array = np.zeros(N)

``````for i in range(N):
### START CODE HERE ### (~ 2 lines of code)
# moderator edit: code removed
### END CODE HERE ###

return L_array
``````

L_array = L_of_omega_array(omega_array, prices_A, prices_B)

1 Like

@Cyrus_W_Smith
The error is that you’r passing L_of_omega to grad while L_of_omega is a function you defined above, all you need is use L_of_omega and pass omega_array[i] and i hope that will work.

1 Like

Thanks Mohammad. I tried the below and now it doesn’t seem to execute the code: No errors, no output.

# This is why it is better to take N = 1001, not N = 1000

N = 1001
omega_array = np.linspace(0, 1, N, endpoint=True)

# This is organised as a function only for grading purposes.

def L_of_omega_array(omega_array, pA, pB):
N = len(omega_array)
L_array = np.zeros(N)

``````for i in range(N):
### START CODE HERE ### (~ 2 lines of code)
# moderator edit: code removed
### END CODE HERE ###

return L_array
``````

L_array = L_of_omega_array(omega_array, prices_A, prices_B)

1 Like

Ok, the code seemed to work, but I got very different values. Any thoughts on where I went wrong?

# This is why it is better to take N = 1001, not N = 1000

N = 1001
omega_array = np.linspace(0, 1, N, endpoint=True)

# This is organised as a function only for grading purposes.

def L_of_omega_array(omega_array, pA, pB):
N = len(omega_array)
L_array = np.zeros(N)

for i in range(N):
### START CODE HERE ### (~ 2 lines of code)
# moderator edit: code removed
### END CODE HERE ###

``````return L_array
``````

L_array = L_of_omega_array(omega_array, prices_A, prices_B)
print(“L(omega = 0) =”,L_array[0])
print(“L(omega = 1) =”,L_array[N-1])
L(omega = 0) = 34935.965
L(omega = 1) = 34935.965
Expected Output
L(omega = 0) = 110.72
L(omega = 1) = 27.48

1 Like
1. Please do not post your code on the forum. That’s not allowed by the Code of
Conduct. If a mentor needs to see your code, we’ll contact you with instructions. I’ll edit this thread to remove the code.

2 Likes

My apologies for posting the code. Everything in the assignment now runs and passed except for the following:

Test case “extra_check”. Wrong output of dLdOmega_of_omega_array for omega_array =
[0. 0.1 0.2 0.3 0.4 0.5
0.6 0.7 0.8 0.90000004 1. ]
Test for index i = 5.
Expected:
-83.240036
Got:
-83.239990234375
7 Tests passed
1 Tests failed

Not sure how this could happen, but it caused me to fail the assignment. Everything else passed. Any thoughts?

1 Like

Check your private messages in a few minutes.

Also, be sure you’re using the current version of the w1_unittest.py file.

It was updated in early Sept 2023, so check the date on your copy. You can find it via the notebook Files menu.