Curve translation in Python does not reach expected value


Suppose I have two curves, f(x) and g(x), and I want to evaluate if g(x) is a translation of f(x).
I used Sympy Curve to do the job with the function translate. However, I need help to reach the correct result. Consider the two functions:

f(x) = -x^2 and g(x) = -(x+5)^2 + 8

Notice that g is vertically translated by 8 and horizontally translated by 5. Why at is not equal to b in the following Python code?

from sympy import expand, Symbol, Curve, oo

x = Symbol('x')
f = -x**2
g = -(x+5)**2+8

a = Curve((x, f), (x, -oo, oo))
at = a.translate(5,8)
b = Curve((x, g), (x, -oo, oo))

a, at, b, at == b
>>> (Curve((x, -x**2), (x, -10, 10)),
 Curve((x + 5, 8 - x**2), (x, -10, 10)),
 Curve((x, 8 - (x + 5)**2), (x, -10, 10)),

How could I make this analysis work using this or any other method?

Asked By: marcelo.guedes



Curve is probably not the right way to do this. If you have univariate functions for which you want to know a x and y translation will make them equal, you could use something like the following:

>>> dx,dy = Symbols('dx dy')
>>> eq = Eq(f.subs(x,x-dx)+dy)
>>> solve_undetermined_coeffs(eq,g),(dx,dy),x)
[(-5, 8)]

If there are no values of dx and dy that will solve the equality, then an empty list will be returned.

Answered By: smichr

Thanks to @smichr for the reference about solve_undetermined_coeffs. Here you can find a full answer to my initial problem in Python 3.8.10 and Sympy 1.11.1.

from sympy import symbols, Eq, solve_undetermined_coeffs

x, dx, dy = symbols('x dx dy')
f = -x**2
g = -(x+5)**2+8

eq = Eq(f.subs(x,x-dx)+dy,g)
Answered By: marcelo.guedes
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.