Created
October 3, 2024 17:47
-
-
Save sujyrokimora/821ac48c1c1d4ec2a388859a24367134 to your computer and use it in GitHub Desktop.
Codigo de LP 03-10-2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def f(x): | |
| a=2.0 | |
| b=3.0 | |
| c=4.0 | |
| return a*x**2+b*x+c | |
| def ff(f,a,b,N): | |
| dx= (b-a)/N | |
| for i in range(N): | |
| y=f(a+i*dx)*dx | |
| yield y | |
| def area_recur(f,a,b,i,N=100): | |
| dx= (b-a)/N | |
| if i==0: | |
| return 0.0 | |
| else: | |
| return f(a+i*dx)*dx + area_recur(f,a,b,i-1,N) | |
| def area(f,a,b,N=100): | |
| soma=0.0 | |
| dx=(b-a)/N | |
| for i in range(N): | |
| soma+=f(a+i*dx)*dx | |
| pass | |
| return soma | |
| def main(): | |
| a=-1.0 | |
| b=2.0 | |
| N=100 | |
| soma=area(f,a,b) | |
| soma2=area_recur(f,a,b,N,N) | |
| gen=ff(f,a,b,N) | |
| soma3= sum(next(gen) for i in range(N)) | |
| print("A={}\nB={}\nC={}".format(soma,soma2,soma3)) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment