How to plot a Graph - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: How to plot a Graph (/thread-3293.html) |
How to plot a Graph - Kamo - May-11-2017 Hello, I have an equation and need to plot a graph using the Euler method, the code looks like this: h = 0.01 x = [0.0] y = [0] n = int(30/h) def f(y,x): eq = #something return #something for i in range (0,n): xn = (i+1)*h yn = y[i] + f(y[i],x[i])*h x.append(xn) y.append(yn) #print (x[i],y[i]) plt.plot(x,y) plt.xlabel("Time(t)") plt.ylabel("Concentration(Cs)") plt.title("Concentration by Time") plt.show()But I have an equation, this one: 10(105 + log(900)) -5*t = S^2 /2 +20S +20log(S) So when t = 0, S = 30. So I need to plot the values of S as the time increase. Any help how to solve the equation?? In fact, I need anything that use the euler method that allows me to plot the graph. Thanks in advance! RE: How to plot a Graph - Larz60+ - May-11-2017 See this example: https://matplotlib.org/users/pyplot_tutorial.html RE: How to plot a Graph - zivoni - May-12-2017 It might help to say what do you mean with "plotting graph using euler method" - euler method usually means numerical method to solve first order ODE - and if you mean this method, then solving ODE and plotting result are two rather separate things. Anyway your equation is not a differential equation, you can transform it to an explicit form as t = f(S) and then straigtly plot it with matplotlib as Larz60+ suggested. And if you instist on using implicit equation, there is plot_implicit() function in sympy.plotting .
|