It hurts just looking at this huge if blocks and I will not refactor it for you.
Didn't see the issues that @bowlofred noticed
as to the error - learn how to debug and how to handle errors. And the Index error message is clear, but anyway
Didn't see the issues that @bowlofred noticed
as to the error - learn how to debug and how to handle errors. And the Index error message is clear, but anyway
i-1+13
will produce invalid index for i >= 366import numpy as np h=500+29/2 kc=50 ks=5 t=20 h=500 km=(kc+ks)/2 q=10^7 dx=.002 zarayeb=np.zeros([377,377]) savabet=np.zeros([377]) def where(i): if i in [53,183,313]: return 'paye' elif i ==1: return 'gushchappaiin' elif i in range(2,12): return 'marzchap' elif i==13: return 'gushchapbala' elif i in [26,39,52,65,78,91,104,117,286,299,312,325,338,351,364]: return 'marzbala' elif i==130 or i==260: return 'ghushchipbala' elif i in[143,156,169,182,195,208,221,234,247]: return 'marzchipbala' elif i==377: return 'gushrastbala' elif i in range(366,377): return 'marzrast' elif i==365: return 'gushrastpaiin' elif i in [14,27,40,66,79,92,105,118,131,144,157,170,196,209,222,235,248,261,274,287,300,326,339,352]: return 'marzpaiin' elif i in [129,128,127]: return 'marzchipchap' elif i in [259,258,257]: return 'marzchiprast' elif i in [139,152,165,178,191,204,217,230,243]: return 'marzchippaiin' elif i==126: return 'gushchipchappaiin' elif i==256: return 'gushchiprastpaiin' elif i in [142,155,168,181,194,207,220,233,246,141,154,167,180,193,206,219,232,245,140,153,166,179,192,205,218,231,244]: return 'chip' else: return 'bdn' for i in range(378): try: z=where(i) if z=='paye': zarayeb[i-1,i-1]=1 savabet[i-1]=33 elif z=='gushchappaiin': zarayeb[i-1,i-1]=-2 zarayeb[i-1,i-1+13]=1 zarayeb[i-1,i-1+1]=1 savabet[i-1]=0 elif z=='gushrastpaiin': zarayeb[i-1,i-1]=-2 zarayeb[i-1,i-1-13]=1 zarayeb[i-1,i-1-1]=1 savabet[i-1]=0 elif z=='gushchapbala': zarayeb[i-1,i-1]=-(2+h*dx/ks) zarayeb[i-1,i-1+13]=1 zarayeb[i-1,i-1-1]=1 savabet[i-1]=-h*dx*t/ks elif z=='gushrastbala': zarayeb[i-1,i-1]=-(2+h*dx/ks) zarayeb[i-1,i-1-13]=1 zarayeb[i-1,i-1-1]=1 savabet[i-1]=-h*dx*t/ks elif 'marzchap': zarayeb[i-1,i-1]=-4 zarayeb[i-1,i-1+13]=2 zarayeb[i-1,i-1-1]=1 zarayeb[i-1,i-1+1]=1 savabet[i-1]=0 elif 'marzrast': zarayeb[i-1,i-1]=-4 zarayeb[i-1,i-1-13]=2 zarayeb[i-1,i-1-1]=1 zarayeb[i-1,i-1+1]=1 savabet[i-1]=0 elif 'marzchipbala': zarayeb[i-1,i-1]=-(4+2*dx*h/kc) zarayeb[i-1,i-1-13]=1 zarayeb[i-1,i-1+13]=1 zarayeb[i-1,i-1-1]=2 savabet[i-1]=-(2*h*dx*t/kc+q*dx**2/kc) elif 'marzchipchap': zarayeb[i-1,i-1]=-(ks+kc+2*km) zarayeb[i-1,i-1-13]=ks zarayeb[i-1,i-1+13]=kc zarayeb[i-1,i-1-1]=km zarayeb[i-1,i-1+1]=km savabet[i-1]=-(q*dx**2/2) elif'marzchprast': zarayeb[i-1,i-1]=-(ks+kc+2*km) zarayeb[i-1,i-1-13]=kc zarayeb[i-1,i-1+13]=ks zarayeb[i-1,i-1-1]=km zarayeb[i-1,i-1+1]=km savabet[i-1]=-(q*dx**2/2) except IndexError as er: print(f'i = {i}') print(er)
Output:i = 366
index 378 is out of bounds for axis 1 with size 377
i = 367
index 379 is out of bounds for axis 1 with size 377
i = 368
index 380 is out of bounds for axis 1 with size 377
i = 369
index 381 is out of bounds for axis 1 with size 377
i = 370
index 382 is out of bounds for axis 1 with size 377
i = 371
index 383 is out of bounds for axis 1 with size 377
i = 372
index 384 is out of bounds for axis 1 with size 377
i = 373
index 385 is out of bounds for axis 1 with size 377
i = 374
index 386 is out of bounds for axis 1 with size 377
i = 375
index 387 is out of bounds for axis 1 with size 377
i = 376
index 388 is out of bounds for axis 1 with size 377
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs