Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
25 views
2 pages
Zero Fonction - Py
Uploaded by
Yasser Rghaoui
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Download now
Download
Save Zero Fonction.py For Later
Download
Save
Save Zero Fonction.py For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
25 views
2 pages
Zero Fonction - Py
Uploaded by
Yasser Rghaoui
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Download now
Download
Save Zero Fonction.py For Later
Carousel Previous
Carousel Next
Download
Save
Save Zero Fonction.py For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 2
Search
Fullscreen
1 #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
2 # UIASS > CPGE > MPSI >
[email protected]
3 #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
4 #
5 # Zero de fonction
6 #
7 #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
8 import numpy as np
9 import scipy.optimize as spo
10 import matplotlib.pyplot as plt
11 #~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
12 def f( x ): return (x-3)**3+4
13 #return (x*x+ np.cos(9*x))*np.sin(x)-2+1/np.exp(x)
14 #~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
15 def fp( x ): return 3*(x-3)**2
16 #~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
17 def dichotomie(f, a, b, epsl=10**-5):
18 if f(a)*f(b) > 0: return None
19 while True:
20 c = (a+b)/2
21 if abs(f(c)) < epsl : return c #if b-a < eps : return c
22 if f(a)*f(c) < 0: b = c
23 else : a = c
24 ## plt.plot(c, 0, ".", color="red")
25 #~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
26 def newton(f, x, fp, epsl=10**-5, maxIter=100):
27 k = 0
28 for i in range(maxIter):
29 #if fp(x) == 0: return None
30 z = x - f(x)/fp(x)
31 if abs(z-x) < epsl: break # if abs(f(z)) < epsl: return z
32 x = z
33 return z
34 ## plt.plot(z, 0, "*", color="green")
35 #~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
36 def Sequante(f, a, b, epsl=10**-5, maxIter=1000):
37 x = ( a*f(b)-b*f(a) ) / ( f(b)-f(a) )
38 for i in range(maxIter):
39 if abs( f(x) ) < epsl: return x
40 b, a = x, b
41 #if f(b)-f(a) == 0: return None
42 x = ( a*f(b) - b*f(a) ) / ( f(b)-f(a) )
43 ## W = np.linspace(0, f(x), 25)
44 ## plt.plot([x]*len(W), W, "--", color="cyan")
45 #~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
46 def Regula_Falsi(f, a, b, epsl=10**-5, maxIter=1000):
47 for i in range(maxIter):
48 x = ( a*f(b)-b*f(a) ) / ( f(b)-f(a) )
49 if abs(f(x)) < epsl : return x #if b-a < eps : return x
50 if f(a)*f(x) < 0: b = x
51 else : a = x
52 ## W = np.linspace(0, f(x), 25)
53 ## plt.plot([x]*len(W), W, "--", color="orange")
54 #~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
55 fig, ax = plt.subplots()
56 ax.grid(True, which='both')
57
58 ax.spines[ 'left'].set_position('zero') ; ax.spines['right'].set_color('none')
59 ax.spines['bottom'].set_position('zero') ; ax.spines[ 'top'].set_color('none')
60 ax.yaxis.tick_left() ; ax.xaxis.tick_bottom()
61
62 a, b = 0, 10 # a, b = -np.pi, np.pi #a, b = 0, 2.4
63 X = np.linspace( a, b, 200 ) ; Y = f(X) ; plt.plot(X, Y, lw=2, color="blue")
64
65 x0 = dichotomie(f, a, b) ; plt.plot(x0, f(x0), "*", lw=3, color="red")
66 x0 = spo.bisect(f, a, b) ; plt.plot(x0, f(x0), "*", lw=5, color="pink")
67
68 x1 = newton(f, b, fp) ; plt.plot(x1, f(x1), "D", lw=3, color="green")
69 x1 = spo.newton(f, b, fp) ; plt.plot(x1, f(x1), "D", lw=5, color="lime")
70
71 x2 = Sequante(f, a, b) ; plt.plot(x2, f(x2), "o", lw=3, color="cyan")
72 x2 = spo.newton(f, a) ; plt.plot(x2, f(x2), "o", lw=5, color="purple")
73
74 x3 = Regula_Falsi(f, a, b) ; plt.plot(x3, f(x3), "s", lw=3, color="orange")
75 plt.show() # plt.savefig("myPlot.png")
76
You might also like
applications_f(x)=0
PDF
No ratings yet
applications_f(x)=0
4 pages
ME685_Assign2_210769-1
PDF
No ratings yet
ME685_Assign2_210769-1
13 pages
EulerOrdre1 Py
PDF
No ratings yet
EulerOrdre1 Py
1 page
EAlab Codes
PDF
No ratings yet
EAlab Codes
6 pages
Function: 'ERROR, Inserte Otros Valores Iniciales'
PDF
No ratings yet
Function: 'ERROR, Inserte Otros Valores Iniciales'
13 pages
Untitled
PDF
No ratings yet
Untitled
6 pages
Punto Fijo: F (X) Cos (X) + X
PDF
No ratings yet
Punto Fijo: F (X) Cos (X) + X
5 pages
Matlab Code
PDF
No ratings yet
Matlab Code
23 pages
ppt code
PDF
No ratings yet
ppt code
32 pages
Python MAC-4
PDF
No ratings yet
Python MAC-4
25 pages
Ejericicio #2
PDF
No ratings yet
Ejericicio #2
4 pages
qst 10 TEST (1)
PDF
No ratings yet
qst 10 TEST (1)
1 page
Matlab Codes
PDF
No ratings yet
Matlab Codes
20 pages
Initial Value & Integration & Differentiation Cheat
PDF
No ratings yet
Initial Value & Integration & Differentiation Cheat
11 pages
Đ Xuân Trư ng-IEIESB21003-Lab4
PDF
No ratings yet
Đ Xuân Trư ng-IEIESB21003-Lab4
8 pages
Python Cheat Sheet
PDF
No ratings yet
Python Cheat Sheet
2 pages
'Please Enter The Value of N: ' 'Please Enter Your Equation (Function) : ' 'S'
PDF
No ratings yet
'Please Enter The Value of N: ' 'Please Enter Your Equation (Function) : ' 'S'
2 pages
Bisection Method
PDF
No ratings yet
Bisection Method
12 pages
Trabalho MatCompIII
PDF
No ratings yet
Trabalho MatCompIII
2 pages
Metode Bisection
PDF
No ratings yet
Metode Bisection
11 pages
Webwork Inter
PDF
No ratings yet
Webwork Inter
5 pages
ass3doc
PDF
No ratings yet
ass3doc
21 pages
EE 553 Homeworks Moyo
PDF
No ratings yet
EE 553 Homeworks Moyo
27 pages
Assignment III MATLAB CODE
PDF
No ratings yet
Assignment III MATLAB CODE
12 pages
Numerical Assignment
PDF
No ratings yet
Numerical Assignment
8 pages
Document (4) (9) (6)
PDF
No ratings yet
Document (4) (9) (6)
47 pages
Proj.
PDF
No ratings yet
Proj.
3 pages
Matlab Assignment 2 ACTUALL
PDF
No ratings yet
Matlab Assignment 2 ACTUALL
4 pages
Screenshot 2023-12-09 at 11.05.11 AM
PDF
No ratings yet
Screenshot 2023-12-09 at 11.05.11 AM
33 pages
Ex-2-code
PDF
No ratings yet
Ex-2-code
4 pages
ME685_endsem_210009_a3b842de4f35447062632eec7f52bcea26bc978d
PDF
No ratings yet
ME685_endsem_210009_a3b842de4f35447062632eec7f52bcea26bc978d
8 pages
3 2
PDF
No ratings yet
3 2
62 pages
MNCPD
PDF
No ratings yet
MNCPD
1 page
MA311M Assignment 1 - Code Listing: Animesh Renanse - 180108048 September 2020
PDF
No ratings yet
MA311M Assignment 1 - Code Listing: Animesh Renanse - 180108048 September 2020
4 pages
MNCPD
PDF
No ratings yet
MNCPD
1 page
Hossein Gadri Elhattab
PDF
No ratings yet
Hossein Gadri Elhattab
51 pages
assignment_8_report
PDF
No ratings yet
assignment_8_report
13 pages
NMO codes ALL
PDF
No ratings yet
NMO codes ALL
25 pages
Function: F f1 (X) F 9 Exp (-0.7 X) Cos (4 X) - 3.5
PDF
No ratings yet
Function: F f1 (X) F 9 Exp (-0.7 X) Cos (4 X) - 3.5
3 pages
BY_Abdullah Hassan Damad
PDF
No ratings yet
BY_Abdullah Hassan Damad
24 pages
非線性方程式的根
PDF
No ratings yet
非線性方程式的根
17 pages
Computer Assignment
PDF
No ratings yet
Computer Assignment
12 pages
Slip 21
PDF
No ratings yet
Slip 21
3 pages
Merged Document
PDF
No ratings yet
Merged Document
49 pages
While
PDF
No ratings yet
While
3 pages
Assignment 1
PDF
No ratings yet
Assignment 1
15 pages
LL1 MN
PDF
No ratings yet
LL1 MN
18 pages
Đ Xuân Trư ng-IEIESB21003-HW2.2
PDF
No ratings yet
Đ Xuân Trư ng-IEIESB21003-HW2.2
11 pages
January 2022
PDF
No ratings yet
January 2022
8 pages
Python
PDF
No ratings yet
Python
10 pages
EEE 554 Matlab Solutions
PDF
No ratings yet
EEE 554 Matlab Solutions
7 pages
Scilab Codes Sem III
PDF
No ratings yet
Scilab Codes Sem III
15 pages
Documento de Marcus v. (1)
PDF
No ratings yet
Documento de Marcus v. (1)
1 page
grad_full
PDF
No ratings yet
grad_full
6 pages
Numerical Method For Engineering 3
PDF
No ratings yet
Numerical Method For Engineering 3
9 pages
Python
PDF
No ratings yet
Python
8 pages
Vtu Maths Lab
PDF
No ratings yet
Vtu Maths Lab
48 pages
Exercise 17.2
PDF
No ratings yet
Exercise 17.2
12 pages
Analytic Geometry: Graphic Solutions Using Matlab Language
From Everand
Analytic Geometry: Graphic Solutions Using Matlab Language
Ing. Mario Castillo
No ratings yet
150+ C Pattern Programs
From Everand
150+ C Pattern Programs
Hernando Abella
No ratings yet
License R2017a.lic
PDF
50% (2)
License R2017a.lic
8 pages
EXCEL Intermediate Practice Activities
PDF
No ratings yet
EXCEL Intermediate Practice Activities
4 pages
Name License Platforms Co-Simulation Model Exchange Co-Simulation Model Exchange
PDF
No ratings yet
Name License Platforms Co-Simulation Model Exchange Co-Simulation Model Exchange
4 pages
Abaqus Book
PDF
No ratings yet
Abaqus Book
212 pages
1 21 8
PDF
No ratings yet
1 21 8
2 pages
2D practical no 1
PDF
No ratings yet
2D practical no 1
9 pages
Upyter Notebook1
PDF
No ratings yet
Upyter Notebook1
5 pages
Statistical Package
PDF
No ratings yet
Statistical Package
5 pages
Array-Numpy-Quiz - Attempt Review
PDF
No ratings yet
Array-Numpy-Quiz - Attempt Review
10 pages
Ansys Workbench Va Kha Nang NG Du N
PDF
No ratings yet
Ansys Workbench Va Kha Nang NG Du N
24 pages
Lab de Control Analogo - PDF Tarea 5 FLOWER ARIAS
PDF
No ratings yet
Lab de Control Analogo - PDF Tarea 5 FLOWER ARIAS
17 pages
0ppm PJPK 2023
PDF
No ratings yet
0ppm PJPK 2023
22 pages
Buổi 10 - Bài tập 1 (Python)
PDF
No ratings yet
Buổi 10 - Bài tập 1 (Python)
3 pages
Salary Sleep Answer Key
PDF
No ratings yet
Salary Sleep Answer Key
53 pages
Get The Training You Need!: Excel PR O
PDF
No ratings yet
Get The Training You Need!: Excel PR O
10 pages
EXCEL Intermediate Practice Activities
PDF
No ratings yet
EXCEL Intermediate Practice Activities
4 pages
Creating Excel Spreadsheet With More Than One Page
PDF
No ratings yet
Creating Excel Spreadsheet With More Than One Page
28 pages
CheatSheet Octave PDF
PDF
No ratings yet
CheatSheet Octave PDF
1 page
Sheet 25
PDF
No ratings yet
Sheet 25
5 pages
Python GTU Study Material E-Notes 3 16012021061619AM
PDF
No ratings yet
Python GTU Study Material E-Notes 3 16012021061619AM
36 pages
NX Nastran 8 Design Sensitivity and Optimization User's Guide
PDF
No ratings yet
NX Nastran 8 Design Sensitivity and Optimization User's Guide
310 pages
ActiveModels HR7
PDF
No ratings yet
ActiveModels HR7
8 pages
(Untitled) : This Spreadsheet Was Created by Either POM, QM or POM-QM For Windows, V4
PDF
No ratings yet
(Untitled) : This Spreadsheet Was Created by Either POM, QM or POM-QM For Windows, V4
7 pages
2D Geo
PDF
No ratings yet
2D Geo
37 pages
1.a Numpy Code
PDF
No ratings yet
1.a Numpy Code
2 pages
Abc Pharma - Sales Performance Dashboard
PDF
No ratings yet
Abc Pharma - Sales Performance Dashboard
6 pages
Jadwal Piket Shift Operator Gardu Induk Tess
PDF
No ratings yet
Jadwal Piket Shift Operator Gardu Induk Tess
6 pages
Hands On NumPy?-1
PDF
No ratings yet
Hands On NumPy?-1
27 pages
Catering Elfmenda
PDF
No ratings yet
Catering Elfmenda
9 pages
Labview Core 2 Course Manual_ Instruments Not for Distribution _ PDF _ Control Flow _ Subroutine
PDF
No ratings yet
Labview Core 2 Course Manual_ Instruments Not for Distribution _ PDF _ Control Flow _ Subroutine
270 pages
Documents
Teaching Methods & Materials