Page 1 sur 1

How to pass variable name to function in program

Publié : mer. janv. 11, 2023 1:40 am
par XcasEngGuy
I am trying to pass a variable name into a function to include in a command. I want a function that can, for example:

eq=3*x^2+x
int_test(eq,x)

such that it can integrate the equation stored in eq by x. yielding:

int(3*x^2+x,x)

i can't get it to stop doing this:

int(3^x^2+x,<the variable name in the program>)

Matt

Re: How to pass variable name to function in program

Publié : mer. janv. 11, 2023 11:32 am
par parisse
I'm confused. Perhaps you just need to quote the variable name '('x' instead of x)?

Re: How to pass variable name to function in program

Publié : mer. janv. 11, 2023 5:44 pm
par XcasEngGuy
I discovered:

eq:=-1/18*L^2*w+5/9*L*w*x-1/2*w*x^2
ind_var:=x
eval(expr(int,eq,ind_var))

works