Hello friends
In my informatics study I am running this program and encounter an error while connecting via ssh:
'''
a*x**2 + b*x + c = 0
roots(a, b, c)
returns floats when real solution, or complex when complex solution.
'''
#the code for the function
def roots(a, b, c):
"""The root(a, b, c) function solves x for a quadratic equation:
a*x**2 + b*x + c = 0
"""
from numpy.lib.scimath import sqrt
x1 = (-b + sqrt((b)**2 - 4.*a*c))/(2.*a)
x2 = (-b - sqrt((b)**2 - 4.*a*c))/(2.*a)
return x1, x2
To easily test this function I have made a test function to include in the program:
#test functions for float and complex numbers
def test_roots_float():
"""Tests the function root(a, b, c) for floats.
Returns True if the function works for floats.
"""
ax1 = 0.0 #known solution for x1
ax2 = -1.0 #known solution for x2
x1, x2 = roots(2, 2, 0) #solve for known solution
if abs(ax1 - x1) == 0 and abs(ax2 - x2) == 0: #test
return True
return False
def test_roots_complex():
"""Tests the function root(a, b, c)
for complex numbers. Returns True if the
function works for complex solutions.
"""
ax1 = (-0.5+0.5j) #known solution for x1
ax2 = (-0.5-0.5j) #known solution for x2
x1, x2 = roots(2, 2, 1) #solve for known solution
if abs(ax1 - x1) == 0 and abs(ax2 - x2) == 0: #test
return True
return False
#run
print 'Test results:'
#test run for floats
test1 = test_roots_float()
if test1:
test1 = 'works'
print 'The function roots(a, b, c) %s for float type\
solutions.' % test1
#test run for complex
test2 = test_roots_complex()
if test2:
test2 = 'works'
print 'The function roots(a, b, c) %s for complex\
type solutions.' % test2
The program works fine while run on a local university computer, but then there is something happening when importing modules while connected via ssh:
... ImportError: libifport.so.5: cannot open shared object file: No such file or directory
What is this error? And is there a solution?