Message Boards Message Boards

0
|
1694 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Use a build-in function within a custom function?

Posted 6 years ago

How do you make a function composition that has a built in function like Maximize inside? For a simple example say with Minimize, let

f[x_]:=x^2
min[x_]:=Minimize[f[x]]

Something of this idea (obviously not syntax correct, I cant find a way to make it work), how would I go about doing this? Such that I can reference to the Minimized function later in the file and change it by changing the f(x) function.

POSTED BY: Alex C
2 Replies

I wonder if you mean something like this:

min[f_] := Minimize[f[x], x];
f[x_] := x^2;
g[x_] := x^4 - x^2;
min[f]
min[g]
POSTED BY: Gianluca Gorni
Posted 6 years ago

Yes! Thats what I meant, thanks a lot; Now the follow up question is how can I swap the variables to minimize, for instance in your snippet if you do /.x->a it would change x to a everywhere, but what if I have a multivariable function to minimize and I want to add or take variables away (not just change them) so for instance:

min[f_] := Minimize[f[x,y,z], x,y,z];

what if id want to, for instance change x to a and not use the other 2, so Id want to get:

min[f_] := Minimize[f[a], a];

out of calling the previous function, because otherwise I have to redefine everything in the minimize function again since it will complain that it cant find the other variables.

POSTED BY: Alex C
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract