Home > database >  Translation from Mathcad to Python
Translation from Mathcad to Python

Time:10-18

I can't translate a formula from Mathcad to Python. Stuck on "a". Here's what I was able to do:

from matplotlib import pyplot as plt
import numpy as np
k1 = 1
b = 1.51
D = (1/b) * (np.sqrt(k1/np.pi))
x0 = 10 * b

myArray = np.arange(0, 24, 0.1)

for t in myArray:
    S1_t = (k1) / (1   np.e ** (-(D * myArray - 5)))
    S1_deistv = S1_t.real
plt.plot(myArray, S1_deistv, color="black")
plt.show()

CodePudding user response:

As you can see, MathCad is going to:

  1. create an expression containing the symbolic derivative of S1.
  2. finding the root of that expression.

In Python, we have to use different libraries to achieve the same result. In this particular case it is a little bit more convoluted (requires more steps). In particular:

  1. Use enter image description here

    result     fjac: array([[-1.]])
         fun: array([-6.66133815e-16])
     message: 'The solution converged.'
        nfev: 6
         qtf: array([3.5682568e-13])
           r: array([-0.22395716])
      status: 1
     success: True
           x: array([18.06314347])
    a =  18.063143471730815
    k =  0.04715849105203411
    

    enter image description here

  • Related