You are on page 1of 7

PROBLEM 3:

In R2, the weighted inner product is given by


⟨ x , y ⟩ = ax1y1 + bx2y2

Where a and b are positive. Find a weighted inner product such that the graph
represents a unit circle as

In that inner product space, reflect that unit circle about an input plane.
1. Theory:
a. Inner product:
Let V be a vector space. The inner product of 2 vectors u, v ∈ V is a real number
satisfying 4 following axioms:
- 1 ∀u ∈ V : (u, u) ≥ 0, ” = ” occurs ⇔ u = 0
- 2 ∀α ∈ K, u, v ∈ V : (αu, v) = α(u, v)
- 3 ∀u, v ∈ V : (u, v) = (v, u)
- 4 ∀u, v, w ∈ V : (u + v, w) = (u, w) + (v, w)
A vector space V + inner product = inner product space
b. Norm of a vector:
- ‖u‖ = √ ( u ,u )

2. Algorithm :
Given data : ⟨ x , y ⟩ = ax1y1 + bx2y2
Where a and b are positive, ‖u‖ = 1

( a 0)
we have x(x1; x2) = (-2; 2) ⇒ ⟨ x , y ⟩ = 0 b

⇒ ⟨ x , x ⟩ = ax1y1 + bx2y2 = 4a + 4b

( a 0)
we have y(y1; y2) = (-3; 3) ⇒ ⟨ x , y ⟩ = 0 b

⇒ ⟨ y , y ⟩ = 9a + 9b

⇒ √ ( 4 a+4 b )2 + ( 9 a+ 9 b )2 = ‖u‖ = 1

3. Code :
import math
print('We have: <x,y> = ax1y2 + bx2y2 ')
m = [['a',0],[0,'b']]
print('<x,y> =')
for i in range(2):
for j in range(2):
print(m[i][j],end = ' ')
print()
print('x(x1,x2)')
x1 = int(input('Please enter x1: '))
x2 = int(input('Please enter x2: '))
print('<x,x> = ax1x2 + bx2x2 = ',x1*x1,'a','+',x2*x2,'b')
print('y(y1,y2)')
y1 = int(input('Please enter y1: '))
y2 = int(input('Please enter y2: ')) #
print('<y,y> = ay1y2 + by2y2 = ',y1*y1,'a','+',y2*y2,'b')
print('=>
sqrt[(',x1*x1,'a','+',x2*x2,'b',')^2','+','(',y1*y1,'a','+',y2*y2,'b',')^2]=1')
print('to solve a or b we this to slove this function: ')
print(' (',x1*x1,'a','+',x2*x2,'b',')^2','+','(',y1*y1,'a','+',y2*y2,'b',')^2] = 1^2 =
1')
z =int(input('if find a enter :1,find b enter : 2 '))
t1= pow(x1,4) + pow(y1,4)
t2= pow(x2,4) + pow(y2,4)
t3= pow(x1,2)*pow(x2,2) + pow(y1,2)*pow(y2,2)
if z == 1:
b = float(input('please enter b: '))
delta = pow(2*b*t3,2)-4*(t1*(pow(b,2)*t2-1))
if delta == 0:
a1=a2=(-2*b*t3)/(2*t1)
print('value : ',a1)
elif delta < 0:
print('no value')
elif delta > 0:
a1 = (-2 * b * t3 + math.sqrt(delta)) / (2 * t1)
a2 = (-2 * b * t3 - math.sqrt(delta)) / (2 * t1)
print('a1 value: ', a1, ' ', 'a2 value: ', a2)
elif z == 2:
a = float(input('please enter a: '))
delta = pow(2 * a * t3, 2) - 4 *( t2 *(pow(a, 2)*t1-1))
if delta == 0:
b1=b2=(-2*a*t3)/(2*t2)
print('value : ',b1)
elif delta < 0:
print('no value')
else:
b1 = (-2 * a * t3 + math.sqrt(delta)) / (2 * t2)
b2 = (-2 * a * t3 - math.sqrt(delta)) / (2 * t2)
print('a1 value: ', b1, ' ', 'a2 value: ', b2)

4. Explaination:

The provided code is Python script that solves linear algebra equation
involving variables ' a ' and ' b '.

1) The script begins by importing the ‘ math ‘ module, which


provides mathematical functions and constants.
2) It prints the string 'We have: <x,y> = ax1y2 + bx2y2 ' to provide
information about the equation being used.
3) It initializes a 2x2 matrix ‘m’ with values [['a', 0], [0, 'b']]. This
matrix represents the coefficients a and b used in the equation.
4) The code prints the string '<x,y> =' to indicate the following output
will display the matrix ‘m’.
5) It uses nested loops to iterate over the rows and columns of the
matrix ‘m’ and prints each element with a space in between.
6) The code then prompts the user to enter values for ‘x1’ and ‘x2’
using the ‘input()’ function, and converts the input to integers
using ‘int()’.
7) It prints the equation ‘'<x, x> = ax1x2 + bx2x2 =
',x1*x1,'a','+',x2*x2,'b'’, substituting the input values and
coefficients. This equation calculates the value of ‘<x, x>’ based
on the provided inputs.
8) Similarly, the code prompts the user to enter values for ‘y1’ and
‘y2’ and converts the input to integers.
9) It prints the equation ‘'<y,y> = ay1y2 + by2y2 =
',y1*y1,'a','+',y2*y2,'b'’, which calculates the value of ‘<y, y>’
based on the provided inputs.
10) The code then prints the equation ‘'=>
sqrt[(',x1*x1,'a','+',x2*x2,'b',')^2','+','(',y1*y1,'a','+',y2*y2,'b',')^2]=
1'’, which represents the equation for the square root of the sum of
the squares of ‘<x, x>’ and ‘<y, y>’, set equal to 1
11) It prints the string 'to solve a or b we this to solve this function: '
as an indication of the approach to find the values of ‘a’ or ‘b’.
12) The code prompts the user to enter a value for ‘z’ using ‘input()’ .
‘z' represents the choice to find either ‘a’ or ‘b’. The input is
converted to an integer using ‘int()’.
13) It calculates intermediate values ‘t1’, ‘t2’, and ‘t3’ based on the
input values of ‘x’ and ‘y’. These calculations are used in the
subsequent steps.
14) If ‘z’ is equal to 1, the code executes the block of code under the
‘if’ statement. This block is for finding the value of ‘a’.
a. It prompts the user to enter a value for ‘b’ and converts the
input to a float using ‘float()’.
b. It calculates the discriminant ‘delta’ based on the quadratic
formula and the given coefficients and inputs.
c. If ‘delta’ is equal to 0, it calculates the value of ‘a1’ and ‘a2’
based on a special case formula and prints the result.
d. If ‘delta’ is less than 0, it prints the string ‘'no value'’.
e. If ‘delta’ is greater than 0, it calculates the values of ‘a1’ and
‘a2’ using the quadratic formula and prints the results.
15) If ‘z’ is equal to 2, the code executes the block of code under the
elif statement. This block is for finding the value of ‘b’.
a. It prompts the user to enter a value for ‘a’ and converts the
input to a float.
b. It calculates the discriminant ‘delta’ based on the quadratic
formula and the given coefficients and inputs.
c. If ‘delta’ is equal to 0, it calculates the value of ‘b1’ and ‘b2’
based on a special case formula and prints the result.
d. If ‘delta’ is less than 0, it prints the string ‘'no value'’.
e. If ‘delta’ is greater than 0, it calculates the values of ‘b1’ and
‘b2’ using the quadratic formula and prints the results.

16) Finally, the code outputs the calculated values of ‘a’ or ‘b’ based
on the user's choice.

It's worth noting that the code assumes valid input values and does not
include extensive error handling or input validation. If incorrect or invalid
input is provided, the script may encounter errors or produce unexpected
results.

You might also like