-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths2p1.py
54 lines (39 loc) · 1.35 KB
/
s2p1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# session 2
# functions
# problem num. 1
import sympy as sp
# Define the symbol and function
x = sp.symbols('x')
f = sp.Function('f')
# Given equation: f(4x + 1) + 2f(3) = 2x + 5
equation = f(4*x + 1) + 2*f(3) - (2*x + 5)
# To find f(-1), we need to find a relationship or solve for f
# Let's substitute x with a specific value to create equations
# Let's choose x = 0 and x = 1 to create two equations
# Substituting x = 0
eq1 = equation.subs(x, 0)
# Substituting x = 1
eq2 = equation.subs(x, 1)
# Now we have two equations:
# eq1: f(1) + 2f(3) = 5
# eq2: f(5) + 2f(3) = 7
# To solve for f(-1), we need another equation involving f(-1)
# Let's substitute x = -1 in the original equation
eq3 = equation.subs(x, -1)
# Now we have three equations:
# eq1: f(1) + 2f(3) = 5
# eq2: f(5) + 2f(3) = 7
# eq3: f(-3) + 2f(3) = 3
# We need to express f(1), f(5), and f(-3) in terms of f(3)
# Let's assume f is linear, i.e., f(x) = a*x + b
a, b = sp.symbols('a b')
f_linear = a*x + b
# Substitute f_linear into the equations
eq1_linear = eq1.subs(f, f_linear)
eq2_linear = eq2.subs(f, f_linear)
eq3_linear = eq3.subs(f, f_linear)
# Solve the system of equations for a and b
solution = sp.solve([eq1_linear, eq2_linear, eq3_linear], (a, b))
# Now, find f(-1) using the linear function
f_minus_1 = f_linear.subs(x, -1).subs(solution)
print(f"The value of f(-1) is: {f_minus_1}")