How could I translate this Python code to Matlab?
Show older comments
I have this python code that I would like to convert to Matlab code. Could anyone help me understand what is going on and help convert from one language to the other?
The code is as follows:
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
def f(s,t):
a = 1.5
b = a
c = a
E = 1
Input = 1
x = s[0]
y = s[1]
z = s[2]
dxdt = Input - a * E * np.power(x, 0.5)
dydt = a * E * np.power(x, 0.5) - b * np.power(y, 0.5)
dzdt = b * np.power(y, 0.5) - c * np.power(z, 0.5)
return [dxdt, dydt, dzdt]
t = np.linspace(0, 10, 100)
s0 = [1, 1, 1]
s = odeint(f,s0,t)
l = 1
plt.plot(t,s[:,0],'b', linewidth=l)
plt.plot(t,s[:,1],'r', linewidth=l)
plt.plot(t,s[:,2],'g', linewidth=l)
plt.xlabel("time (t)")
plt.ylabel("Concentration (X, Y, Z)")
plt.legend(["X", "Y", "Z"])
plt.show()
Answers (0)
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!