Post Reply 
diff command doesn'texecute in a program
08-10-2024, 12:20 PM
Post: #1
diff command doesn'texecute in a program
In below program, diff command doesn't execute in CAS view, any suggestion?
EXPORT DERIVADA()

BEGIN
LOCAL fx, x, n, resultado;

// Solicitar al usuario la función y el orden de la derivada
INPUT({{fx,[-1],{27,73,0}},
{n,[0],{46,10,1}}},
{"Derivada de una función f(x)"},{"Funcion f(x):","Orden de la derivada:"},{"",""});

// Definicion de la variable independiente x
x := 'x';

// Calculo de la derivada de orden n de la función f(x)
resultado := diff(fx,x,n);

// Mostrar el resultado
PRINT();
PRINT("Función original: "+fx);
PRINT("Derivada de orden "+n+": "+resultado);

// Devolver el resultado
RETURN resultado;

END;
Find all posts by this user
Quote this message in a reply
08-11-2024, 07:06 AM
Post: #2
RE: diff command doesn'texecute in a program
Hello Victor

What worked for me was to store the expression with the derivative in a string variable (cmd), then use the CAS and EVAL functions. EVAL was necessary because, if not used, the program returned an unevaluated string.

Code:
EXPORT derivada()

BEGIN
local fx, n, cmd, resultado;

// Solicitar al usuario la función y el orden de la derivada
INPUT({{fx,[-1],{27,73,0}},
{n,[0],{46,10,1}}},
{"Derivada de una función f(x)"},{"Funcion f(x):","Orden de la derivada:"},{"",""});

// Calculo de la derivada de orden n de la función f(x)
 cmd:="simplify(diff("+fx+",x,"+n+")";
 resultado:=CAS(EVAL(cmd));

// Mostrar el resultado
PRINT();
PRINT("Función original: "+fx);
PRINT("Derivada de orden "+n+": "+resultado);

// Devolver el resultado
RETURN resultado;

END;


Hope this helps,

Regards.
Find all posts by this user
Quote this message in a reply
08-14-2024, 01:30 PM
Post: #3
RE: diff command doesn'texecute in a program
Thank you, Patocuy for the helpful tip.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)