Previous Up Next

6.16.6  Defining a function with history: as_function_of

The as_function_of command creates a function defined by an expression, even if the desired variable already has a value.


Example.
Input:

a:=sin(x)

Output:

sin
x

Input:

b:=sqrt(1+a^2)

Output:

1+sin2x

Input:

c:=as_function_of(b,a)

Output:

(a) -> { return(sqrt(1+a^2));}

Input:

c(x)

Output:

1+x2


Warning !!
If the variable b has been assigned several times, the first assignment of b following the last assignment of a will be used. Moreover, the order used is the order of validation of the commandlines, which may not be reflected by the Xcas interface if you reused previous commandlines.


Example.
Input:

a:=2 b:=2*a+1 b:=3*a+2 c:=as_function_of(b,a)

Output:

(a) -> {return(2*a+1);}

So c(x) is equal to 2*x+1. But: Input:

a:=2
b:=2*a+1
a:=2
b:=3*a+2
c:=as_function_of(b,a)

Output:

(a) -> {return(3*a+2);}

So c(x) is equal to 3*x+2.
Hence the line where a is defined must be reevaluated before the good definition of b.


Previous Up Next