math - Python: How calculate 2 variable nonlinear equation or plot those equation on graph in python? -


i hope gain solutions (x , y) 2 nonlinear equations. write code, , insert equations, not work.

as know, problem generated @ f2=math.acos(~~~) , "valueerror: math domain error" (actually, when erase math.acos , show wrong specific solution.)

so, please ask know way, (1) how gain solution of 'f1=~', 'f2=~' x, y. (2) how draw plot 'sub_equation=~' , 'f1=~'.

i looking help. thank you.

from scipy.optimize import fsolve import math import numpy np import matplotlib.pyplot plt     ###input### angle = 120.0 length_porpyrin =18.6 length_linker = 12.5 ###parameter### length_1 = length_porpyrin/2.0 lenght_2 = length_linker/2.0 delta = np.pi*angle/180.0/2.0 ramda = 30.18/180.0*np.pi bond_angle = 2.0*np.pi/3.0 length_d = 1.35    def equations(p):     x,y = p     ### modified variable ###     atr1 = np.arctan(length_1 / x)     atr2 = np.arctan(lenght_2 / y)     sub_equation = ( length_d ** 2+(y/np.cos(np.arctan(lenght_2 / y))) ** 2-(x/np.cos(np.arctan(length_1 / x))) ** 2 )*np.cos(np.arctan(lenght_2 / y)) / ( 2 * length_d * y )     ##########################     f1 = (  (x/np.cos(np.arctan(length_1 / x))) ** 2 + (y/np.cos(np.arctan(lenght_2 / y))) ** 2 - 2 *( x/np.cos(np.arctan(length_1 / x))) * (y/np.cos(np.arctan(length_1 / x))) *  np.cos(ramda-np.arctan(length_1 / x)-np.arctan(lenght_2 / y))  ) - length_d ** 2     f2 = math.acos(sub_equation)  -  ( bond_angle -(np.pi-np.arctan(lenght_2 / y)-delta))     return (f1, f2)   solution = fsolve(equations, (25,25)) radius1 = solution[0] radius2 = solution[1]    print('[solution]') print(solution) print('radius1', radius1) print('radius2', radius2) 

i think error might in fact when use inverse trig function (like arccos (acos), arcsin (asin)). inverse trig functions have domains, , if value happens plugged in out of domain, result in domain error.

below domains of each inverse trig function (r = real nums):

inverse trig function domains

so solution put kind of bounds on parameter can entered inverse (arc) functions. or try handling exception using try except block. here's python documentation that: https://docs.python.org/3/tutorial/errors.html (go section 8.3).


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -