Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Chinamath
- # Juhani Kaukoranta 12.11.2023
- import numpy as np
- import scipy.optimize as opt
- # minimoitava funktio x^2 + y^2
- # huom muuttujat x = x[0], y = y[0]
- def f(x):
- return x[0]**2 + x[1]**2
- # rajoitusehto (x+5)^2+(y-12)^2 = 14^2
- def g(x):
- return (x[0] + 5)**2 + (x[1] - 12)**2 - 14**2
- # the rajoitusehdotyyppi, eq=yhtälö, ineg=epäyhtälö,fun=rajoitusehdon funktio
- cons = ({'type': 'eq', 'fun': g})
- x0 = np.array([-1, -1]) # lähtöarvot otettu "hatusta"
- result = opt.minimize(f, x0, constraints=cons)
- print(result.message) # tietoja laskennasta
- print("lausekkeen x^2 + y^2 minimiarvo = ",f(result.x))
- print("minimi saadaan arvoilla x = ",result.x[0]," ja y = ",result.x[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement