Unable to retrieve attribute 'objval' - python

Hoping someone could give me a hand, I am having issues retrieving an optimal value for my code as shown below.
I have found that the status code is 2 which indicates it can be solved and there is an optimal value, I am just unsure why it cannot give me that value.
Please Help, this is a big assignment & I am struggling a lot!.
`mod = gp.Model('Gladstone')
mod.setParam('LogToConsole', 0)
mod.setParam('OutputFlag', 0)
N_investors = 2000
#Add variables
#cost of telephone for each group
t = {1: 15, 2:12, 3:20, 4:18}
#cost of personal for each group
p = {1: 35, 2:30, 3:50, 4:40}
group = [1,2,3,4]
x = mod.addVars(groups, lb=0, vtype=GRB.CONTINUOUS, name = 'personal_group') #number of people contacted in person in group i
y = mod.addVars(groups, lb=0, vtype=GRB.CONTINUOUS, name = 'telephone_group')#number of people contacted in telephone in group i
#Constraints
mod.addConstr((gp.quicksum(x[i] + y[i])for i in groups) == N_investors)
mod.addConstr((x[1] + x[2] + y[1] + y[2]) >= (N_investors))
mod.addConstr((x[1] + x[2] + x[3] + x[4]) >= (0.25 * N_investors))
mod.addConstr((x[1] + x[2] + x[3] + x[4]) >= (0.5* (x[1] + y[1])))
mod.addConstr((x[2] + y[2] + x[4] + y[4]) <=(0.4 * N_investors))
mod.addConstr((x[1] + x[2] + x[3] + x[4] <= (0.25 * (x[2] + y[2] + x[4] + y[4]))))
mod.addConstr((x[1] + y[1]) >= (0.1 * N_investors))
mod.addConstr(((x[2] + y[2])) >= (0.1 * N_investors))
mod.addConstr(((x[3] + y[3])) >= (0.1 * N_investors))
mod.addConstr(((x[4] + y[4])) >= (0.1 * N_investors))
mod.addConstr(((x[1] + y[1])) <= (0.5 * N_investors))
mod.addConstr(((x[2] + y[2])) <= (0.5 * N_investors))
mod.addConstr(((x[3] + y[3])) <= (0.5 * N_investors))
mod.addConstr(((x[4] + y[4])) <= (0.5 * N_investors))
#Objective
costs = (t[1] * y[1]) + (t[2] * y[2]) + (t[3] * y[3]) + (t[4] * y[4]) + (p[1] * x[1]) + (p[2] * x[2]) + (p[3] * x[3]) + (p[4] * x[4])
mod.setObjective(costs, sense = GRB.MINIMIZE)
mod.update()
mod.optimize()
print(mod.objval)`

Related

How do I calculate quantization error of 2 tuples in python

I'm currently trying to code Floyd-Steinberg dithering in python
When trying to add colour in Floyd-Steinberg dithering, you have to calculate the "quantization error" of 2 tuples.
How would I go about doing this?
Converting them to grayscale doesn't produce good results, and I'm not sure how I would get it to work.
I don't want help with any other part of my code, just the quantization error.
Here is my code :
from PIL import Image
import sys,math
imag = Image.open(sys.argv[1])
palette = [(0,0,0,255),(255,255,255,255),(255,0,0,255),(0,255,0,255),(0,0,255,255)]
def distance(co1, co2):
return pow(abs(co1[0] - co2[0]), 2) + pow(abs(co1[1] - co2[2]), 2)
def palcol(col,pal):
return min(pal, key=lambda x: distance(x, col))
for y in range(imag.height-1):
for x in range(imag.width-1):
oldpixel = imag.getpixel((x,y))[0] * 299/1000 + imag.getpixel((x,y))[1] * 587/1000 + imag.getpixel((x,y))[2] * 114/1000
newpixel = palcol(imag.getpixel((x,y)),palette)[0] * 299/1000 + palcol(imag.getpixel((x,y)),palette)[1] * 587/1000 + palcol(imag.getpixel((x,y)),palette)[2] * 114/1000
querror = oldpixel - newpixel
newpixel = palcol(imag.getpixel((x,y)),palette)
imag.putpixel((x,y),newpixel)
imag.putpixel((x + 1,y ),tuple([round(imag.getpixel((x + 1,y ))[0] + (querror*7/16)),round(imag.getpixel((x + 1,y ))[1] + (querror*7/16)),round(imag.getpixel((x + 1,y ))[2] + (querror*7/16)),255]))
imag.putpixel((x - 1,y + 1),tuple([round(imag.getpixel((x - 1,y + 1))[0] + (querror*3/16)),round(imag.getpixel((x - 1,y + 1))[1] + (querror*3/16)),round(imag.getpixel((x - 1,y + 1))[2] + (querror*3/16)),255]))
imag.putpixel((x ,y + 1),tuple([round(imag.getpixel((x ,y + 1))[0] + (querror*5/16)),round(imag.getpixel((x ,y + 1))[1] + (querror*5/16)),round(imag.getpixel((x ,y + 1))[2] + (querror*5/16)),255]))
imag.putpixel((x + 1,y + 1),tuple([round(imag.getpixel((x + 1,y + 1))[0] + (querror*1/16)),round(imag.getpixel((x + 1,y + 1))[1] + (querror*1/16)),round(imag.getpixel((x + 1,y + 1))[2] + (querror*1/16)),255]))
imag.show()

Avoiding value Error into fsolve from scipy.optimize

I'm trying to solve a long block of equations from an EES implementation using the scipy.optimze.fsolve. But in this block of equations there are CoolProp calls that have a range of validation, and sometimes it yields ValueError. I want to know if there is a strategy to avoid ValueError and let fsolve try another guesses.
This is my code:
def block1(x):
def cp_gas(Ti, Tj):
return (1000/(Tj - Ti)*(x[6]*1.25 + x[1]*(0.45 *(((Tj + 273.15)/1000)
-((Ti + 273.15)/1000)) + 1.67*(((Tj + 273.15)/1000)**2 - ((Ti + 273.15)/1000)**2)/2
- 1.27*(((Tj + 273.15)/1000)**3 - ((Ti + 273.15)/1000)**3)/3
+ 0.39*(((Tj + 273.15)/1000)**4 - ((Ti + 273.15)/1000)**4)/4)
+ x[2]*(1.79 *(((Tj + 273.15)/1000) - ((Ti + 273.15)/1000))
+ 0.107*(((Tj + 273.15)/1000)**2 - ((Ti + 273.15)/1000)**2)/2
+ 0.586*(((Tj + 273.15)/1000)**3 - ((Ti + 273.15)/1000)**3)/3
- 0.2*(((Tj + 273.15)/1000)**4 -((Ti + 273.15)/1000)**4)/4)
+ x[3]*(1.11*(((Tj + 273.15)/1000) - ((Ti + 273.15)/1000))
- 0.48*(((Tj + 273.15)/1000)**2 - ((Ti + 273.15)/1000)**2)/2
+ 0.96*(((Tj + 273.15)/1000)**3 - ((Ti + 273.15)/1000)**3)/3
- 0.42*(((Tj + 273.15)/1000)**4 - ((Ti + 273.15)/1000)**4)/4)
+ x[4]*(0.88*(((Tj + 273.15)/1000) - ((Ti + 273.15)/1000))
- 0.0001*(((Tj + 273.15)/1000)**2 - ((Ti + 273.15)/1000)**2)/2
+ 0.54*(((Tj + 273.15)/1000)**3 - ((Ti + 273.15)/1000)**3)/3
- 0.33*(((Tj + 273.15)/1000)**4 - ((Ti + 273.15)/1000)**4)/4)
+ x[5]*(0.37*(((Tj + 273.15)/1000) - ((Ti + 273.15)/1000))
+ 1.05*(((Tj + 273.15)/1000)**2 - ((Ti + 273.15)/1000)**2)/2
- 0.77*(((Tj + 273.15)/1000)**3 - ((Ti + 273.15)/1000)**3)/3
+ 0.21*(((Tj + 273.15)/1000)**4 - ((Ti + 273.15)/1000)**4)/4)))
f = np.zeros(26)
# x[24] = T_out_vent
f[0] = x[0] - cp_gas(T0, Tgas5)
f[1] = m_gas_teoria_conferindo*x[8] - x[9]*0.8 - x[7]
f[2] = x[10] + x[8] - (x[7] + x[9]*0.8)
f[3] = x[9] - x[8]*Z
f[4] = x[12] + x[13] + x[14] + x[15] + x[16] + x[17] - x[11]
f[5] = x[12] - M_CO2*x[8]/x[7]
f[6] = x[13] - M_H2O*x[8]/x[7]
f[7] = x[14] - M_N2*x[8]/x[7]
f[8] = x[15] - M_O2*x[8]/x[7]
f[9] = x[16] - M_SO2*x[8]/x[7]
f[10] = x[17] - (M_Cz*x[8] - 0.8*x[9])/x[7]
f[11] = x[18] - (e*a*((1-omega_ar) + 3.76*(1-omega_ar) + omega_ar)*(MM_ar_CBG)/(MM_CBG)*x[19])
f[12] = x[1] - ((m_gas5-x[7])*FM_g_CO2+x[7]*x[12])/(x[7]*x[11]+(m_gas5-x[7])*FM_g)
f[13] = x[2] - ((m_gas5-x[7])*FM_g_H2O+x[7]*x[13])/(x[7]*x[11]+(m_gas5-x[7])*FM_g)
f[14] = x[3] - ((m_gas5-x[7])*FM_g_N2+x[7]*x[14])/(x[7]*x[11]+(m_gas5-x[7])*FM_g)
f[15] = x[4] - ((m_gas5-x[7])*FM_g_O2+x[7]*x[15])/(x[7]*x[11]+(m_gas5-x[7])*FM_g)
f[16] = x[5] - (x[7]*x[16])/(x[7]*x[11]+(m_gas5-x[7])*FM_g)
f[17] = x[6] - (x[7]*x[17])/(x[7]*x[11]+(m_gas5-x[7])*FM_g)
f[18] = x[20] - x[21]/rho_ar_in
f[19] = (1/3600)*x[21] - (x[10]+x[18])
f[20] = ((x[10]+x[18])*h_in_vent + x[22]) - (x[10] + x[18])*x[23]
f[21] = x[23] - HAPropsSI('H', 'T', x[24] + 273.15, 'P', P_out_vent*1e3, 'W', omega_ar)/1e3
f[22] = x[22] - (0.000012523*x[20] + 0.054570445)
f[23] = x[25] - HAPropsSI('C', 'T', x[24] + 273.15, 'P', P_out_vent*1e3, 'W', omega_ar)/1e3
f[24] = m_gas5 - (x[7]+x[19]+x[18])
f[25] = eta_total - ((m_gas5*x[0]*(Tgas5-T0) - (x[10]+x[18])*x[25]*(x[24]-T0))
/(x[8]*PCI_RSU + x[19]*PCI_CBG))
return f
x = fsolve(block1, np.ones(26))
The code yields ValueError depending on constant values that are previously defined.
ValueError example:
ValueError: The output for key (8) with value (-nan) is outside the range of validity: (0) to (0.94145) :: inputs were:"H","T",1.3025950731911414e+02,"P",2.0132500000000000e+05,"W",1.0890000000000000e-02
If anyone can help me I will be grateful.
Thank in advance
The function you are running doesn't handle NaN values.
You can use try/except blocks to deal with it.
Or change the NaN values to a 0 (or any suitable number of your choice).
Here is a toy example to help you fix your code. You have to decide what should be the correct behavior and use one of the proposed strategies to deal with NaNs.
import bumpy as np
def f(x):
if np.isnan(x):
raise ValueError('NaN is not supported')
return x**x
test_cases = [1, 2, 3, 4, np.nan, 6, 7]
print('skip in case of error')
for x in test_cases:
try:
print(f(x))
except ValueError:
pass
print()
print('fix X in case of NaN')
for x in test_cases:
if np.isnan(x):
x = 0
print(f(x))
Output:
skip in case of error
1
4
27
256
46656
823543
fix X in case of NaN
1
4
27
256
1
46656
823543

Understanding timesteps in scipy.integrate.odeint

I am trying to solve a PDE using odeint and the method of lines. My code is definitely wrong - and I'm trying to figure out where it is going wrong.
I am calling the ode solver using odeint(odefunc,y0,tspan) where tspan = np.linspace(0.0, 0.5, 5) & y0 = 1.0*np.ones(3).
I tried printing t within odefunc and am confused by the output. Despite the fact that I am solving up to t=0.5, the last t-value to print is 0.015081203121127767. The number of outputs matches tspan, but I cannot see how it could possibly be solving up to t = 0.5 when the last time in the de function is 0.015. What am I missing?
My DE is time dependent - so this is making it very hard to figure out where things are going wrong because I don't seem to be seeing the times where everything fails.
ETA - this is failing, but running this without some of the irrelevant stuff I am getting the warning ODEintWarning: Excess work done on this call (perhaps wrong Dfun type). Run with full_output = 1 to get quantitative information., which I'm assuming is part of the issue - but it doesn't appear to be halting the code.
MWE
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import math
import sys
plt.interactive(False)
sigma = 2320
rho = 1000
gravity = 9.81 # [m/s^2]
g = gravity*3600*3600 # [m/hour^2]
S = 0.01
settlingVelocity = 0.02 # [m/s]
ws = settlingVelocity*3600 # [m/hour]
n = 0.04 # [SI]
J = 400 # [Ws/m]
k = 0.02
Cstar = 0.2 * sigma # [kg/m^3]
W = 2 # [m]
D0 = 1.2
Lw = 20
L = 100
tend = 0.5 # in hours
tspan = np.linspace(0.0, tend, 5)
def d(t): # metres
if t < 50: # hours
return 0.5
else:
return 0.05
def Q(t):
return 3600 * (math.sqrt(S)/n)*((W*d(t))**(5/3))/((2*d(t) + W)**(2/3))
def h(t):
return d(t)/2
def beta(t):
return (sigma - rho) * g * h(t)/sigma
def Omega(t):
return rho * g * S * Q(t) # [W/m]
def PsiTime(t):
return rho * g * Q(t) * (D0 - d(t))/(Lw)
N = 10
X = np.linspace(0, L, N)
delX = L/ (N-1)
def odefunc(y, t):
def zetaEh(t):
return k * (PsiTime(t) + Omega(t)) / (J + beta(t))
def zetaEW(t):
return (2*d(t)/(W + 2*d(t))) * k * Omega(t)/(J + beta(t))
def zetaR(t):
return (W/(W + 2*d(t))) * k*Omega(t)/(beta(t))
def zetaEF(t,i):
return (W/(W + 2*d(t))) * k * Omega(t) / (J + beta(t))
C = y[:N]
M = y[N:]
print("time: ", t)
dCdt = np.zeros(X.shape)
dMdt = np.zeros(X.shape)
dCdt[0] = ( # forward difference for dCdx
-Q(t) / (W*d(t)) * (C[1] - C[0]) / delX
+ (zetaEh(t) / (W * d(t))) * ((Cstar - C[0]) / Cstar)
- (ws * C[0] * (beta(t))) / (d(t) * (J + beta(t)))
)
dMdt[0] = 0
# gully channel
for i in range (1, N-1): # central difference
if M[i] + W *C[i] * ws - zetaR(t) * (Cstar - C[i]) / Cstar < 0:
reMass = M[i] + W * C[i] * ws
dCdt[i] = (
-Q(t) / (W*d(t)) * (C[i+1] - C[i - 1]) / (2*delX)
+ 1 / (W * d(t)) * ((zetaEW(t) + zetaEF(t,i)) * (Cstar - C[i]) / Cstar
+ reMass * (1 - (beta(t))/ (J + beta(t))))
- C[i] * ws/d(t)
)
dMdt[i] = -M[i]
else:
dCdt[i] = (
-Q(t) / (W*d(t)) * (C[i+1] - C[i - 1]) / (2*delX)
+ 1 / (W * d(t)) * (zetaEW(t) + zetaR(t)) * (Cstar - C[i]) / Cstar
- C[i] * ws / d(t)
)
dMdt[i] = W * C[i] * ws - zetaR(t) * (Cstar - C[i]) / Cstar
# Final node - backward difference
if M[N-1] + W * C[N-1] * ws - zetaR(t) * (Cstar - C[N-1]) / Cstar < 0:
reMass = M[N-1] + W * C[N-1] * ws
dCdt[N-1] = (
-Q(t) / (W * d(t)) * (C[N-1] - C[N-2]) / delX
+ 1 / (W * d(t)) * ((zetaEW(t) + zetaEF(t, i)) * (Cstar - C[N-1]) / Cstar
+ reMass * (1 - (beta(t)) / (J + beta(t))))
- C[i] * ws / d(t)
)
dMdt[N-1] = -M[N-1]
else:
dCdt[N-1] = (
-Q(t) / (W * d(t)) * (C[N-2] - C[N - 1]) / delX
+ 1 / (W * d(t)) * (zetaEW(t) + zetaR(t)) * (Cstar - C[N-1]) / Cstar
- C[N-1] * ws / d(t)
)
dMdt[N-1] = W * C[N-1] * ws - zetaR(t) * (Cstar - C[N-1]) / Cstar
dydt = np.ravel([dCdt, dMdt])
return dydt
init_C = 0.0 * np.ones(X.shape)
init_M = 0.0 * np.ones(X.shape)
init= np.ravel([init_C, init_M])
sol = odeint(odefunc, init, tspan)
conc = sol[:, :N]

SyntaxError when running program

I have to make a calculator with argv.sys. When I run my code I keep getting this error:
>>> "C:\Users\admin\Desktop\uni\Informatik BW\assignment.py" + rect 0 0 10 10
File "<stdin>", line 1
"C:\Users\admin\Desktop\uni\Informatik BW\assignment.py" + rect 0 0 10 10
^
SyntaxError: invalid syntax
>>>
Here is my program:
import sys
import math
def area_rectangle(x,y,widht,height):
return (widht*height)
def xy_centroid_rectangle(x,y):
return (k + l * 0.5)
#def area_circle(x,y,r):
#return (r*r*math.pi)
#def xy_centroid_circle(k,r):
# return ((4 * r / 3 * math.pi) * 2)
#def area_half_circle(x,y,r):
# return (r * r * math.pi / 2)
#def xy_centroid_half_circle(k,r):
# return (4 * r / 3 * math.pi)
#def area_right_triangle(x,y,a,h):
# return (a * h / 2)
#def xy_centroid_right_triangle(k,l):
# return (a + h + math.sqrt((a * a) + (h * h)))
x = 0
y = 0
a = 0
fx = 0
fy = 0
f = 0
i = 1
while i < len(sys.argv):
vz = sys.argv[i]
print i
print vz
if sys.argv[i + 1] == "rect":
f = area_rectangle(float(sys.argv[i + 2]),float(sys.argv[i + 3]),float(sys.argv[i + 4]),float(sys.argv[i + 5]))
fx = xy_centroid_rectangle(float(sys.argv[i + 2]),float(sys.argv[i + 4]))
fy = xy_centroid_rectangle(float(sys.argv[i + 3]),float(sys.argv[i + 5]))
i += 6
#if sys.argv[i + 1] == "circ":
#f = area_circle(float(sys.argv[i + 2]),float(sys.argv[i + 3]),float(sys.argv[i + 4]))
#fx = xy_centroid_circle(foat(sys.argv[i + 2]),float(sys.argv[i + 4]))
#fy = xy_centroid_circle(foat(sys.argv[i + 3]),float(sys.argv[i + 4]))
#i += 5
#if sys.argv[i + 1] == "halfcirc":
#f = area_circle(float(sys.argv[i + 2]),float(sys.argv[i + 3]),float(sys.argv[i + 4]))
#fx = xy_centroid_circle(foat(sys.argv[i + 2]),float(sys.argv[i + 4]))
#fy = xy_centroid_circle(foat(sys.argv[i + 3]),float(sys.argv[i + 4]))
#i += 5
#if sys.argv[i + 1] == "righttri":
#f = area_rectangle(float(sys.argv[i + 2]),float(sys.argv[i + 3]),float(sys.argv[i + 4]),float(sys.argv[i + 5]))
#fx = xy_centroid_rectangle(float(sys.argv[i + 2]),float(sys.argv[i + 4]))
#fy = xy_centroid_rectangle(float(sys.argv[i + 3]),float(sys.argv[i + 5]))
#i += 6
if vz == "+":
x = (x * a + fx * f) / (a + f)
y = (y * a + fy * f) / (a + f)
a = a + f
if vz == "-":
x = (x * a - fx * f) / (a - f)
y = (y * a - fy * f) / (a - f)
a = a - f
print x
print y
print a
Why am I getting this error?
That's not how you run a python program. Open a CMD (Windows) prompt and write your command line there. You'll probably need to add python in front too.

Solving 2 Non-Linear Equations

I've been working with this equations of Potential Flow
pSI: 0 = 10 * y + 23.8732414638 * (pi + atan(abs((x - 12) / x))) + 23.8732414638 * (pi - atan(abs((y + 12) / x)))-234.882642242
V: 0 = ((10 + 23.8732414638 * x / (x*2 + (y - 12)*2) + 23.8732414638 * x / (x*2 + (y + 12)*2))**2 + (23.8732414638 * (y - 12) / (x*2 + (y - 12)*2) + 23.8732414638 * (y + 12) / (x*2 + (y + 12)*2))*2)*0.5-8
using the next code to solve them:
# Prototype of N-R for a system of two non-linear equations
# evaluating functions of two variables
from math import *
eq1 = raw_input('Enter the equation 1: ')
eq2 = raw_input('Enter the equation 2: ')
x0 = float(input('Enter x: '))
y0 = float(input('Enter y: '))
def f(x,y):
return eval(eq1)
def g(x,y):
return eval(eq2)
x = x0
y = y0
for n in range(1, 8):
a = (f(x + 1e-06, y) - f(x,y)) / 1e-06
b = (f(x, y + 1e-06) - f(x,y)) / 1e-06
c = - f(x,y)
d = (g(x + 1e-06, y) - g(x,y)) / 1e-06
eE = (g(x, y + 1e-06) - g(x,y)) / 1e-06
fF = - g(x,y)
print "f(x, y)= ", eq1
print "g(x, y)= ", eq2
print """x y """
print x, y
print """a b c d e f """
print a, b, c, d, e, fF
print """
a * x + b * y = c
d * x + e * y = f
"""
print a," * x + ",b," * y = ",c
print d," * x + ",eE," * y = ",fF
_Sy = (c - a * fF / d) / (b - a * eE / d)
_Sx = (fF / d) - (eE / d) * _Sy
Ea_X = (_Sx ** 2 + _Sy ** 2)**0.5
x = x + _Sx
y = y + _Sy
print "Sx = ", _Sx
print "Sy = ", _Sy
print "x = ", x
print "y = ", y
print "|X_1 - X_0| = ", Ea_X
And gives me the Zero division Error
Traceback (most recent call last):
File "C:\Documents and Settings\Principal\Mis documentos\Finished_Non_lin_N_R.py", line 38, in <module>
d = (g(x + 1e-06, y) - g(x,y)) / 1e-06
File "C:\Documents and Settings\Principal\Mis documentos\Finished_Non_lin_N_R.py", line 27, in g
return eval(eq2)
File "<string>", line 1, in <module>
ZeroDivisionError: float division by zero
Then I tried with this one that I've found in one solved question:
from scipy.optimize import fsolve
from math import *
def equations(p):
x, y = p
return ( ((10 + 23.8732414638 * x / (x**2 + (y - 12)**2) + 23.8732414638 * x / (x**2 + (y + 12)**2))**2 + (23.8732414638 * (y -12) / (x**2 + (y - 12)**2) + 23.8732414638 * (y + 12) / (x**2 + (y + 12)**2))**2)**0.5-8, 10 * y + 23.8732414638 * (pi + atan(abs((x - 12) / x))) + 23.8732414638 * (pi - atan(abs((y + 12) / x)))-234.882642242)
x, y = fsolve(equations, (0, 18))
print equations((x, y))
And with the next problem:
<module2>:19: RuntimeWarning: divide by zero encountered in long_scalars
<module2>:19: RuntimeWarning: divide by zero encountered in double_scalars
(-1.3374190643844486e-11, -2.8308022592682391e-11)
And the last part of this story is that I have some code that actually works
but is too clumsy and a little bit inaccurate, and I would like some suggestions in order to make it simple:
from math import *
U = 10
b = 15
h = 12
cF = 0.5 * U * b / pi
pSI0 = 234.882642242
VP = 12.0
X0 = 0
Y0 = 40
sX = 0.01
sY = 0.01
print cF
def FirstFor(A,B,C,D):
for n in range(1,808):
for m in range(1,4002):
X = A - B*n
Y = C - D*m
pSI = U * Y + cF * (pi + atan(abs((Y - h) / X))) + cF * (pi - atan(abs((Y + h) / X)))
Vaprox = ((10 + 23.8732414638 * X / (X**2 + (Y - 12)**2) + 23.8732414638 * X / (X**2 + (Y + 12)**2))**2 +(23.8732414638 * (Y - 12) / (X**2 + (Y - 12)**2) + 23.8732414638 * (Y + 12) / (X**2 + (Y + 12)**2))**2)**0.5
EA1 = abs(pSI0 - pSI)
EA2 = abs(VP - Vaprox)
if EA1 < 0.05 and EA2 < 0.05:
X1f = X
Y1f = Y
H3 = [X1f,Y1f]
print n,m,X,Y,"GG son",EA1,EA2
print H3
for n in range(1,808):
for m in range(1,4002):
X = H3[0] - B*n*0.001
Y = H3[1] - D*m*0.001
pSI = U * Y + cF * (pi + atan(abs((Y - h) / X))) + cF * (pi - atan(abs((Y + h) / X)))
Vaprox = ((10 + 23.8732414638 * X / (X**2 + (Y - 12)**2) + 23.8732414638 * X / (X**2 + (Y + 12)**2))**2 +(23.8732414638 * (Y - 12) / (X**2 + (Y - 12)**2) + 23.8732414638 * (Y + 12) / (X**2 + (Y + 12)**2))**2)**0.5
EA1 = abs(pSI0 - pSI)
EA2 = abs(VP - Vaprox)
if EA1 < 0.0001 and EA2 < 0.0001:
X2f = X
Y2f = Y
I3 = [X2f,Y2f]
print n,m,X,Y,"GG son",EA1,EA2
print I3
for n in range(1,808):
for m in range(1,4002):
X = H3[0] + B*n*0.001
Y = H3[1] + D*m*0.001
pSI = U * Y + cF * (pi + atan(abs((Y - h) / X))) + cF * (pi - atan(abs((Y + h) / X)))
Vaprox = ((10 + 23.8732414638 * X / (X**2 + (Y - 12)**2) + 23.8732414638 * X / (X**2 + (Y + 12)**2))**2 +(23.8732414638 * (Y - 12) / (X**2 + (Y - 12)**2) + 23.8732414638 * (Y + 12) / (X**2 + (Y + 12)**2))**2)**0.5
EA1 = abs(pSI0 - pSI)
EA2 = abs(VP - Vaprox)
if EA1 < 0.0001 and EA2 < 0.0001:
X2f = X
Y2f = Y
I3 = [X2f,Y2f]
print n,m,X,Y,"GG son",EA1,EA2
print I3
# starting with the FirstFor
FirstFor(X0,sX,Y0,sY)
print "\n This should be good"
raw_input()

Categories

Resources