Home > Commands -> Function Commands -> change_var

EXAMPLES ON MY SAGE PAGE - Doing a Change of Variables with Sage

Goal: Create a function change_var(h,oldvar,newfun)) that substitutes the function newfun wherever the variable oldvar occurs in h.

  • Example 1: Suppose f(x)=2x+1 and u(t)=cos(t). Create f(t)=f(u(t)).

    Open a code block and define the programming function change_var. Evaluate. There should be no result.

    # Define the function
    def change_var(h, oldvar, newfun) :
        return h.substitute(oldvar==newfun)

    Now open another code block and enter and then evaluate the following code.

    # Declare the variables used in your functions f and u. Define your functions and then call the programming function.
    var('x t')

Sage commands used:

  • var() to declare the variables.
  • substitute() is in python format

References: Change of variable in integration (see also My Sage Page), Using substitute()

Keywords: function, programming, change, variables, integration, sage