Python Forum
Getting an unexpected generator object ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting an unexpected generator object ?
#11
Thanks,

I am also trying to graph the error vs h with a loglog function, but I have two separate issues.
loglog is not recognized and when I omit it, the graph I obtain is empty.

from scipy import *
import numpy as np
from numpy import array
from scipy import integrate
import matplotlib.pyplot as plt

a=0
b=1
n=500
h=(b-a)/(n)
 
def f(x):
    return x**2
 
def trapezoidal(f,a,b,n):
    return (h/2)*(f(a)+f(b))+h*( sum(f(a+h*i)  for i in range(1, (n-1))))
 
print(trapezoidal(f,a,b,n))
 
# Why this?
lambda x: f(x)
 
c= integrate.quad(f,0,1)
print(c)
 
error=(abs(trapezoidal(f,a,b,n)-c[0]) for n in range (300,900))
print(list(error))
plt.plot((list(error),list(h)) for n in range (300,900))
Reply


Messages In This Thread
RE: Getting an unexpected generator object ? - by mcgrim - Mar-27-2019, 01:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating list of lists from generator object t4keheart 1 2,233 Nov-13-2020, 04:59 AM
Last Post: perfringo
  unexpected object? urufu 2 2,061 Mar-08-2020, 02:35 PM
Last Post: urufu
  receive from a generator, send to a generator Skaperen 9 5,572 Feb-05-2018, 06:26 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020