I tried reading other posts that mentioned this problem and I couldn't understand how to apply them to my situation. Also this is my first time using stack overflow, so I apologize for any formatting errors.
from sympy import *
from math import sqrt
x = symbols('x')
a = symbols('a',positive=True)
f = 1 / ((x**4)*((x**2)-(a**2))**.5)
#Part A
g = f.subs(4*a,x)
h = f.subs(2*a,x)
area=g-h
#Part B
answ = solve(area-5,a)
print ('part a:' , str(area))
print ('part b:' , str(answ[0].evalf()))
I'm trying to get a value to print out.
I also have the same issue in this code block
from sympy import *
x = symbols('x')
# Part A
f = (x**3-4*x+3) / (((x-5)**2)*(x**2+3)*(x**2+5))
print("The partial fraction decomposition of f is :", apart(f), "\n")
# Part B
a = symbols('a', positive=True, constant=True)
g = (x**2+2*x+a) / (x-1)**3*(x**2+1)
print("The partial fraction decomposition of g is :", apart(g, x), "\n")
# Part C
g = apart(g, x)
G1 = integrate(x, (x, 2, 4))
G2 = integrate(2*(a + 3)/(x - 1)**3, (x, 2, 4))
G3 = integrate(2 * (a + 7) / (x - 1)**2, (x, 2, 4))
G4 = integrate((a + 13)/(x - 1), (x, 2, 4))
G5 = integrate(5, (x, 2, 4))
print(G1, G2, G3, G4, G5)
value = solve((G1 + G2 + G3 + G4 + G5 - 1), a)
print((value))
Since a couple people seemed confused, here are the problems I am trying to solve with python.
So I figured it out after talking to my TA for a little bit, if anyone is curious I am going to post the solutions and explanations here with it.
from sympy import *
from sympy.plotting import (plot, plot_parametric,plot3d_parametric_surface, plot3d_parametric_line, plot3d)
part of the issue was importing math for the sqrt() function because it conflicted with sympy's, thereby making it impossible to solve anything.
# Insert code for problem #1 here.
x = symbols('x')
a = symbols('a', positive=True)
f = 1 / ((x**4)*(sqrt((x**2)-(a**2))))
#Part A
F = integrate(f, x)
g = F.subs(x, 4*a)
h = F.subs(x, 2*a)
area = g - h
#Part B
# print(area.evalf())
answ = solve(area-5, a)
print ('part a:', area)
print ('part b:', answ[0].evalf())
The next group of problems was that I mis-used the subs() function, placing the variable I wanted to solve for on the wrong side. I also integrated the function before hand, in order to actually solve for the area under the curve. In order to get a value for answ I used the first value of the vector created along with the evalf() to aproximate it.
# Insert code for problem #3 here.
x = symbols('x')
# Part A
f = (x**3-4*x+3) / (((x-5)**2)*(x**2+3)*(x**2+5))
print("The partial fraction decomposition of f is :", apart(f), "\n")
# Part B
a = symbols('a', positive=True)
g = (x**2+2*x+a) / ((x-1)**3*(x**2+1))
print("The partial fraction decomposition of g is :", apart(g, x), "\n")
# Part C
g = apart(g, x)
# print(g)
# G = integrate(g, (x,2,4))
G1 = integrate((a - 3)/(4*(x - 1)), (x, 2, 4))
G2 = integrate((a - 1)/(2*(x - 1)**2), (x, 2, 4))
G3 = integrate((a + 3)/(2*(x - 1)**3), (x, 2, 4))
G4 = integrate((a*x-3*x)/(4*(x**2 + 1)) , (x, 2, 4))
G5 = integrate((-a-1)/(4*(x**2 + 1)), (x, 2, 4))
value = solve((G1- G2 + G3 - G4- G5 - 1), a)
print("\n", "The answer for part C is:",(value[0].evalf()))
The problem with the next grouping of the code was some simple syntax errors on the g(x) function. I also had to remove the constant=True, this was because it made solving for a impossible.