[Python] Using Jacobian matrix in solve_ivp

Discussão em 'Python' iniciado por Stack, Janeiro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to use the solve_ivp built-in function with the Jacobian matrix. I get this error message:


    UserWarning: The following arguments have no effect for a chosen solver: jac. .format(", ".join("{}".format(x) for x in extraneous)))
    ​

    I am unsure if it is a syntax error or an error in the Jacobian matrix.

    Some of my code

    def MyIntFun(t,y):
    return DivWatFlux(y,t,wPar, sPar, RPar,dzIN, dzN)

    def jacfunc(t,y):
    jac = Richardsmatrix(y, t, wPar, sPar, RPar, dzIN, dzN)
    return jac

    mt.tic()
    hwODE = spi.solve_ivp(MyIntFun, [tout[0], tout[-1]], hw0, method='RK45',
    vectorized=True,rtol=1e-4, jac=jacfunc)
    mt.toc()


    This is the code for the Jacobian:

    def Richardsmatrix(hw, t, wPar, sPar, RPar, dzIN, dzN): #the jacobian (a,b,c)

    K=Kfun(hw, wPar, m)
    kRes =RPar.kRobBotR

    a = np.zeros(nN)
    b = np.zeros(nN)
    c = np.zeros(nN)


    ii=np.arange(1, nN-1)

    a[ii] = K[ii, 0]/(dzIN[ii, 0]*dzN[ii-1, 0]) #middle nodes
    a[0] = 0 #a1l is zero and not in matrix
    a[nN-1] = K[nN-1, 0] / (dzIN[nN-1, 0] * dzN[nN-2, 0])

    b[ii] = -K[ii, 0] / (dzIN[ii,0] * dzN[ii-1,0])- K[ii+1,0] / (dzIN[ii,0] * dzN[ii, 0]) #middle nodes
    b[0] = -K[1, 0]/(dzIN[0 , 0]*dzN[0, 0])- kRes / dzIN[0 ,0]
    b[nN-1] = -K[nN-1, 0] / (dzIN[nN-1, 0] * dzN[nN-2, 0])

    c[ii] = K[ii+1,0] / (dzIN[ii,0] * dzN[ii, 0]) #middle nodes
    c[0] = K[1,0] / (dzIN[0, 0] * dzN[0, 0])
    c[nN-1] = 0

    B = np.diag(a[1:nN], -1)+ np.diag(b, 0) + np.diag(c[0:nN-1], 1)
    sB = sp.sparse.csc_matrix(B)
    return


    My group and I are pretty new at programming, so any help is greatly appreciated!

    Continue reading...

Compartilhe esta Página