How to calculate the values of a function in an entire range when only the values in the integers are known?

Asked

Viewed 68 times

1

someone can help me, please?

I’m trying to write a function in Python (I use 3) that implements the following code that is in Mathematica:

inserir a descrição da imagem aqui

Source:[https://rip94550.wordpress.com/2009/05/13/n-6-scaling-functions-and-mother-wavelets/]

Basically, the problem is this: I need to determine a Phi(t) function over the range [0.5] given the following conditions:

a) Phi(0), Phi(1), Phi(2), Phi(3), Phi(4) and Phi(5) are known.

b) actual K0, K1, K2, K3, K4 and K5 constants are also known.

b) the Phi(t) function is defined recursively:

Phi(t) = sum(ki*Phi(2t-i)) = K0*Phi(2t) + K1*Phi(2t-1) + K2*Phi(2t-2) + K3*Phi(2t-3) + K4*Phi(2t-4) + K5*Phi(2t-5)

I tried using the sympy module creating a polynomial that represented Phi(t):

def phi(h,t):
    norm = math.sqrt(2)
    string = '0 +'
    for k in range(len(h)):
        parameter = norm*h[k]
        string_aux = f'({parameter}*phi[2*t-{k}])+'
        string = string + string_aux
    string = string[:-1]
    pol1 = sym.sympify(string)  

where h is the set of parameters I placed above (item b).

When executing entering the variable "t" previously declared using

t = sympy.symbols('t')

I get the following error:

TypeError: 'Symbol' object is not subscriptable

I don’t know if this is the best way to implement this function because it is still recursive. Can you help me with this error and with the proper implementation of this problem? Thank you all.

  • Review the indentation of the function phi().

  • @Augustovasques in my code she is identada. Thanks for the remark. I will correct here. Hugs.

  • Correct, because just as I did someone else can look at the indentation and recommend closing the question. I’m withdrawing my recommendation as soon as the issue is made.

  • 1

    @Augustovasques correction made! Thank you.

  • I didn’t find that line t = sympy.symbols('t') within the function phi(). I ask you are trying to create a symbol over a local function parameter in a scope outside the function? If it is has no way, that parameter t can only be accessed within the body of the function.

  • @Augustovasques is just that. I’m trying to create outside the function. In general this variable t will appear in other functions also that I’m creating. From what you’re telling me for each of them I need to declare internally, right? I’ll try to do it here. Thank you.

  • @Augustovasques includes the line t = sympy.symbols( ' t ' ) between the last and penultimate line but the error has not changed. Remains identical.

  • The error is not on the line t = sympy.symbols('t'). The error is happening on the line pol1 = sym.sympify(string) there is something wrong with the generated expression 0 +(0.0*phi[2*t-0])+(1.4142135623730951*phi[2*t-1])+(2.8284271247461903*phi[2*t-2])

  • 1

    @Augustovasques I’ll think a little bit more about that line. Thanks. EDIT: One thing I’ve already found. The line that defines pol1 = sym.sympify(string) tem algo de errado na expressão gerada 0 +(0.0*phi[2*t-0])+(1.4142135623730951*phi[2*t-1])+(2.8284271247461903*phi[2*t-2])... is wrong. I should not use brackets. I should use brackets. Editing in my question...

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.