Bottom Page

Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to plot a Graph
#1
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!
Quote
#2
See this example: https://matplotlib.org/users/pyplot_tutorial.html
Quote
#3
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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How do I make my plot show up? ThomasM4 0 209 Dec-09-2018, 05:28 AM
Last Post: ThomasM4
  Tips on surface plot HW question Cwcox 1 266 Nov-14-2018, 11:45 PM
Last Post: Larz60+
  How to customize x axis in matplotlib.pyplot for a scatter plot? wlsa 9 507 Nov-10-2018, 01:32 AM
Last Post: wlsa
  Adding text to plot Pythcoronas 1 328 Sep-13-2018, 12:27 PM
Last Post: baby_quant
  plot the mean in a bar diagram sussii 3 465 May-23-2018, 11:27 PM
Last Post: wavic
  How to plot date series in matplotlib? StrybolData 2 1,929 Jan-25-2018, 07:13 PM
Last Post: StrybolData
  Removing data in a plot ulrich48155 3 1,338 Jun-19-2017, 06:31 PM
Last Post: zivoni
  matplotlib : Raster Plot adithyakrish 0 1,109 Apr-24-2017, 10:46 AM
Last Post: adithyakrish
  Change the colour of a plot Sito 1 995 Apr-13-2017, 10:22 PM
Last Post: zivoni
  Creating a colored Contour Plot Metwx87 3 1,358 Feb-21-2017, 10:14 AM
Last Post: zivoni

Forum Jump:


Users browsing this thread: 1 Guest(s)