maple evaluate function of variables containing x

568 Views Asked by At

The problem

Well this is basically the problem. I want to evaluate a function but the variable x is defined inside a, so for some reason maple doesn't substitute 7 for x.

2

There are 2 best solutions below

0
On

Using substitution works:

    |\^/|     Maple 17 (X86 64 LINUX)
._|\|   |/|_. Copyright (c) Maplesoft, a division of Waterloo Maple Inc. 2013
 \  MAPLE  /  All rights reserved. Maple is a trademark of
 <____ ____>  Waterloo Maple Inc.
      |       Type ? for help.
> a := 3*x+5;
                                 a := 3 x + 5

> f := subs(val=a, x -> val);
                               f := x -> 3 x + 5

> f(7);
                                      26
0
On
a := 3*x + 5;

f := unapply(a, x);

And then call f(7); etc.

In the incorrect way you were trying before you were mixing up the global name x with the procedure's formal parameter x.

This is a Maple FAQ and the unapply command is intended for doing this kind of thing.