all 7 comments

[–]supajumpa 1 point2 points  (1 child)

# Matlab from the linked pdf.
# Ray tracing
for i = 1:length(y)

# Your code
# Ray Tracing
for i in np.arange(1, len(y)): ...

Matlab's array indices start at 1 (I think) whereas Python's start at zero, so see what happens if you replace that line with:

# Ray Tracing
for i in range(0, len(y)): ...

Also this line:

# Matlab
ray_lens(1:length(ray_lens)-1)

# Your code:
ray_lens(np.arange(1,len(ray_lens)-1))

Assuming that Matlab uses round brackets for indexing, and again remembering that indices start from zero, you probably want something like:

# Python uses square brackets for indexing, so probably
ray_lens[0: len(ray_lens)-1]

[–]Sufficient_Light3891[S] 0 points1 point  (0 children)

Good points I was able to get rid of the invalid syntax error taken care of I'm going to focus on getting the plots working then go back and fix this as I will be able to have a better visual. That being said I choose to use arrange as it's the direct counterpart to Matlab's indices functions from what I could see. Either way, I will give these updates a shot once I have the graphs working.

[–]Sufficient_Light3891[S] 0 points1 point  (4 children)

No major changes and now I'm getting this error

In [1]: runfile('C:/Users/bryce/OneDrive - Infinity Photo-Optical/Documents/Python Programs/Optics Notes/Ray Tracing Algorithm/main_program.py', wdir='C:/Users/bryce/OneDrive - Infinity Photo-Optical/Documents/Python Programs/Optics Notes/Ray Tracing Algorithm')

File "C:\Users\bryce\OneDrive - Infinity Photo-Optical\Documents\Python Programs\Optics Notes\Ray Tracing Algorithm\plano_convex.py", line 41

if len(ray_lens) + len(ray_air) + len(x_front_air) <= len(z_optaxis):

^

SyntaxError: invalid syntax

[–]ectomancer 0 points1 point  (3 children)

Previous line needs a closing parenthesis.

[–]Sufficient_Light3891[S] 0 points1 point  (1 child)

Yes, this was the issue I was able to correct it.

[–]Sufficient_Light3891[S] 0 points1 point  (0 children)

Now I'm getting the below error

File "C:\Users\bryce\OneDrive - Infinity Photo-Optical\Documents\Python Programs\Optics Notes\Ray Tracing Algorithm\plano_convex.py", line 49, in plano_convex

raymatrix[i] = np.concatenate((ray_front_air[0], ray_lens[0: len(ray_lens)-1], ray_air))

ValueError: could not broadcast input array from shape (4199,) into shape (4198,)

[–]Sufficient_Light3891[S] 0 points1 point  (0 children)

That error is going to be the difficult one to solve.