Example #1
0
def DerivEquation(equation, unknownNum, deriTime):
    rawFuncList = [equation]
    undefList = [unknownNum]
    rawFuncList2 = []
    funcList = []
    # 全部等式标准化
    for func in rawFuncList:
        rawFuncList2.append(ESFC.NormalizationEquation_1(func))
    ESI.WriteLog("Normalized all the equation:")
    ESI.WriteLog(str(rawFuncList2))

    # 全部等式移项
    for func in rawFuncList2:
        subFuncLeft = func.split("=")[0]
        subFuncRight = func.split("=")[1]
        subFuncRightList = ESFC.MultiSimplify(subFuncRight)
        # 逐个移项
        for item in subFuncRightList:
            if item[0] == "+":
                subFuncLeft += "-" + item[1]
            else:
                subFuncLeft += "+" + item[1]
        funcList.append(subFuncLeft)
    ESI.WriteLog("Simplified all the equation:")
    ESI.WriteLog(str(funcList))

    solveTarget = ""
    for char in undefList:
        solveTarget += char + ","
    solveTarget = solveTarget[:len(solveTarget) - 1]

    resEquation = sp.diff(funcList[0], solveTarget, deriTime)
    print ESI.WriteLog("Derivation resunt: " + str(resEquation))
    return resEquation
Example #2
0
def MultiSimplify(equation):
    ESI.WriteLog("Try to simplify multi equation...")
    #最终输出结果
    simplifiedEquation = []
    #补上加号
    if equation[0] != "-" and equation[0] != "+":
        equation = "+" + equation
    ESI.WriteLog("'+' added, the equation now is: " + equation)

    #获取各个单项式的去符号结果
    rightEquationContents = equation.replace("+", " ").replace("-",
                                                               " ").split(" ")
    rightEquationContents.remove("")

    #获取各个单项式符号
    rightSymbols = []
    for char in equation:
        if char == "+":
            rightSymbols.append("+")
        elif char == "-":
            rightSymbols.append("-")

    #将单项式(去符号)与单项式合并写入返回值列表
    currentIndex = 0
    for contents in rightEquationContents:
        simplifiedEquation.append([rightSymbols[currentIndex], contents])
        #递增指针
        currentIndex += 1

    ESI.WriteLog("Split complete, the equation now is: " +
                 str(simplifiedEquation))

    #返回处理结果
    return simplifiedEquation
Example #3
0
def PurifyEquation(equation):
    ESI.WriteLog("Purify the equation" + str(equation))
    PureEquation = ""
    for char in equation:
        if char != " ":
            PureEquation += char
    ESI.WriteLog("Purified equation: " + str(PureEquation))
    return PureEquation
Example #4
0
def SelfCheck():
    ESI.WriteLog("====================SYSTEM CHECKING LOG====================")
    ESI.WriteLog("System checking start...")
    ESI.CheckDir(currentDir, ESI.logFileDir, ESI.logFile)
    ESI.CheckDir(currentDir, ESI.equationFileDir, ESI.equationFile)
    ESI.CheckDir(currentDir, ESI.undefFileDir, ESI.undefFile)
    ESI.CheckDir(currentDir, ESI.funcFileDir, ESI.funcFile)
    ESI.WriteLog(
        "====================SYSTEM CHECKING COMPLETE====================")
Example #5
0
def AddUnknown(unknown):
    addedUndef = unknown
    if not addedUndef in letters:
        print ESI.WriteLog("You are adding a unknown not in the letters list")
    else:
        if addedUndef in ESI.ReadUndef():
            print ESI.WriteLog(
                "You are adding a unknown that exist in the unknown list")
        else:
            ESI.WriteUndef(addedUndef)
Example #6
0
def SolveEquations(rawFuncList, undefList, resPrint=True):
    rawFuncList2 = []
    funcList = []
    # 全部等式标准化
    for func in rawFuncList:
        rawFuncList2.append(ESFC.NormalizationEquation_1(func))
    ESI.WriteLog("Normalized all the equation:")
    ESI.WriteLog(str(rawFuncList2))

    # 全部等式移项
    for func in rawFuncList2:
        subFuncLeft = func.split("=")[0]
        subFuncRight = func.split("=")[1]
        subFuncRightList = ESFC.MultiSimplify(subFuncRight)
        # 逐个移项
        for item in subFuncRightList:
            if item[0] == "+":
                subFuncLeft += "-" + item[1]
            else:
                subFuncLeft += "+" + item[1]
        funcList.append(subFuncLeft)
    ESI.WriteLog("Simplified all the equation:")
    ESI.WriteLog(str(funcList))

    solveTarget = ""
    for char in undefList:
        solveTarget += char + ","
    solveTarget = solveTarget[:len(solveTarget) - 1]

    solution = sp.solve(funcList, solveTarget)
    # print ESI.WriteLog("SOLUTION:" + solution)
    solveIndex = 1
    if resPrint:
        for solve in solution:
            print ESI.WriteLog("Solution" + str(solveIndex) + ":")
            for unknown in undefList:
                print ESI.WriteLog(unknown + ":" +
                                   str(solve[sp.Symbol(str(unknown))]))
            solveIndex += 1
        return solution
    else:
        return solution
Example #7
0
    ESI.WriteLog(str(funcList))

    solveTarget = ""
    for char in undefList:
        solveTarget += char + ","
    solveTarget = solveTarget[:len(solveTarget) - 1]

    resEquation = sp.diff(funcList[0], solveTarget, deriTime)
    print ESI.WriteLog("Derivation resunt: " + str(resEquation))
    return resEquation


#====================开机自检log系统====================
ESI.CheckLogDir()
for i in range(0, 5):
    ESI.WriteLog("\n")
#====================开机自检log系统====================


#====================系统自检====================
def SelfCheck():
    ESI.WriteLog("====================SYSTEM CHECKING LOG====================")
    ESI.WriteLog("System checking start...")
    ESI.CheckDir(currentDir, ESI.logFileDir, ESI.logFile)
    ESI.CheckDir(currentDir, ESI.equationFileDir, ESI.equationFile)
    ESI.CheckDir(currentDir, ESI.undefFileDir, ESI.undefFile)
    ESI.CheckDir(currentDir, ESI.funcFileDir, ESI.funcFile)
    ESI.WriteLog(
        "====================SYSTEM CHECKING COMPLETE====================")