I want to define function f_n:=x^n in maple in such a way that if i enter f_3 is should get x^3. i'm unable to do so, please help me in this regard. Thank you in advance.
2026-03-29 20:26:17.1774815977
On
Defining a function with variable in subscript
264 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
2
There are 2 best solutions below
0
On
Here is one way of using a procedure call of an indexed name.
f := proc(x)
if procname::indexed then
x^op(1,procname);
else error "procedure name called without an index";
end if;
end proc:
f[3](x);
3
x
f[-2](x);
1
----
2
x
f[a](x);
a
x
f(x);
Error, (in f) procedure name called without an index
If you are operating in 2D Input mode in the Maple GUI (its default) then in the following way you can enter an indexed name that appears as a subscripted name. Example, for the 2D Input of f[3] to appear as f-subscripted-by-3 you can enter these keystrokes:
f CtlShift_ 3 ie. Ctl-Shift-underscore together
That is quite different from the keystrokes,
f __ 3 , ie. f__3
which produces a special kind of name that (by design) gets prettyprinted as subscripted.
There are two types of indeces - literal (
a__n) and indexed (a[n]) - but neither works in the way you want as far as I know.You can define a two variable function:
f:=(n,x)->x^n. This should work the way you want. E.g. an $f_3(x)$ would be accessed asf(3,x).The two variable function will not show in indexed notation, but except for that it should provide what want.