Define function cmd

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 554
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Define function cmd

Message par compsystems » mer. avr. 28, 2021 10:19 pm

Hello
I want to define a function where the expression is stored in a variable, but it does not call the content of the variable

expr1 := 'x^3 - 2*x^2 + 1*x -1'; [enter] x^3-2*x^2+1*x-1
function f(x)=expr1; end; [enter] (x)->nop(expr1) excepted (x)->x^3-2*x^2+1*x-1
function f(x) expr1; end;
f := function(x) expr1; end;
f:=(x) -> expr1;
f(x):=expr1;
f(x):=eval(expr1);

http://www-fourier.ujf-grenoble.fr/~par ... fr297.html

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: Define function cmd

Message par parisse » jeu. avr. 29, 2021 2:57 pm

I don't understand what you want to do. If you want to define a function from an expression, the command is unapply. For example
g:=x^2-1;
f:=unapply(g,x);

compsystems
Messages : 554
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: Define function cmd

Message par compsystems » jeu. avr. 29, 2021 11:15 pm

ok, "unapply" works fine

Répondre