Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to use the solution of Maximize, defined as a function, in another function. Here's an example:

f1[y_] := x /. Last[Maximize[{Sin[x y], Abs[x] <= y}, x]]  (* or any other function *)

This definition is fine, for example if I give f1[4], I get the answer -((3 \[Pi])/8).

The problem is that when I want to use it in another function I get an error. For example:

FindRoot[f1[y] == Pi/4, {y, 1}]

Gives me the following error:

ReplaceAll::reps: {x} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

FindRoot::nlnum: The function value {-0.785398+(x/.x)} is not a list of numbers with dimensions {1} at {y} = {1.}. >>

I've been struggling with this for several days now! Any comment, idea, help, ... is deeply appreciated!

share|improve this question

marked as duplicate by Szabolcs, Verbeia Mar 1 '13 at 4:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Try evaluating f[y] alone and you'll see that the function f, a you defined it, simply isn't compatible with symbolic arguments. –  Szabolcs Mar 1 '13 at 4:00
    
Actually I'd say duplicate of this: mathematica.stackexchange.com/q/333/12 The answer I gave there explains the issue and the solution more clearly. –  Szabolcs Mar 1 '13 at 4:01
    
Also see here: support.wolfram.com/kb/3820 –  Szabolcs Mar 1 '13 at 4:03
    
Thank you very much Szabolcs! –  user2122036 Mar 1 '13 at 4:17