I have to form a Jacobi matrix with the following code. The rows of Jacobi are values of function residual.residual. and with each outer loop, the columns are added to Jacobi. Problem is I do not know how to use the index on variable 'Rop'.
I used the given index in matlab and it works fine there. but I guess I need to change it for python.
for i1 in range(1,nxt-1):
for j1 in range(1,nyt-1):
Rop=();Rsp=();Rsgp=()
pit[i1,j1]=pit[i1,j1]+ep;
sit[i1,j1]=sit[i1,j1]+es;
sgit[i1,j1]=sgit[i1,j1]+es;
for i in range(1,nxt-1):#inner loop to calculate perturbed residual
for j in range(1,nyt-1):
if (index[i,j]!=0):
rop,rwp,rgp=residual.residual(pit,sw,sg,i,j,boold,bwold,bgold,
swold,sgold,rsoold,rswold,index,
delx, dely, depth, phi, kx, ky,
ax, ay, h, delt, qo, nxt, nyt, welin,
Vb, pvtgas, pvtoil, pvtw, relpermgo,
relpermow, time, it,fmult)
Rop[count:count+2,col]+=(rop/ep,rwp/ep,rgp/ep)
rop,rwp,rgp=residual.residual(po,sit,sg,i,j,boold,bwold,bgold,
swold,sgold,rsoold,rswold,index,
delx, dely, depth, phi, kx, ky,
ax, ay, h, delt, qo, nxt, nyt, welin,
Vb, pvtgas, pvtoil, pvtw, relpermgo,
relpermow, time, it,fmult)
Rop[count:count+2,col+1]+=(rop/es,rwp/es,rgp/es)
rop,rwp,rgp=residual.residual(po,sw,sgit,i,j,boold,bwold,bgold,
swold,sgold,rsoold,rswold,index,
delx, dely, depth, phi, kx, ky,
ax, ay, h, delt, qo, nxt, nyt, welin,
Vb, pvtgas, pvtoil, pvtw, relpermgo,
relpermow, time, it,fmult)
Rop[count:count+2,col+2]+=(rop/es,rwp/es,rgp/es)
MATLAB uses 1-based indexing, while Python uses 0-based indexing.
Try changing all your ranges from the form range(1,nxt-1)
to range(nxt)
, which will give you a sequence from 0
to nxt-1
, inclusive. The long form is range(0, nxt)
.
It's hard to tell where you want to stop based on your code, but if you want to stop before nxt-1
just adjust the last argument of range accordingly.
I'm not sure how to advise you on Rop[count:count+2,col]
, since you haven't shown how count
is defined.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.