Reputation: 194
Please, tell me how use functions in Maxima? I tried this
function(g, u):= (print(g(0)), print(u));
function(x^2, 10);
but it doesn't work
Upvotes: 1
Views: 563
Reputation: 178
When defining a function F(Y)
you want Y
to be a x
-dependent input variable for the former, right?
You can directly define the a function F
of unknown variable Y
and then input some function as argument.
(%i_) F(Y) := diff(Y(t),t) + Y(t^2);
F(sin);
(%o_) F(Y):='diff(Y(t),t,1)+Y(t^2)
(%o_) sin(t^2)+cos(t)
and you are done!
If you try to parse F(foo(x)):=something + foo(x)
you get
define: in definition of F, found bad argument foo(x)
There is a more specific way I took from maxima: use function as function argument:
Before defining F(foo)
, you can tell maxima
"by foo
I mean foo(x)
": depends(foo,x)
.
Then you can define a function with variable foo
, for example
depends(foo,x);
F(foo) := foo(x^2) + foo(x) + diff(foo(x),x) ;
F(sin);
Upvotes: 0
Reputation: 17595
I guess you want to evaluate the first argument with a specific value of the second argument. So maybe you want ev(g, x=0)
instead of g(0)
.
(g(0)
works only if g
is the name of a function or a lambda expression, i.e., an unnamed function.)
Maybe you can explain in more detail what you want to accomplish.
Upvotes: 3