example62

import os
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import brentq
os.chdir(r'D:\projects\wordpress\ex52')
os.getcwd()
f=lambda x: 0.2+x * np.cos(3/x)
x=np.linspace(-1,1,1000)
plt.plot(x,f(x))
plt.axhline(0,color='k')
xstar=brentq(f,-0.7,-0.5)
print(xstar,f(xstar))
plt.plot(xstar,f(xstar), &#039;ro&#039;)<br />
plt.text(-1.0, -0.5, &#039;x=%6.4f and f(x)=%6.4f&#039; % (xstar, f(xstar)))
plt.tight_layout()
plt.savefig(&quot;example52.png&quot;, dpi=300)
plt.show()
plt.close()

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading