Dan
I first define the function
f[a_?NumberQ]:=x/.Last[FindRoot[xSCos[a x],{x,.4}]]
and it evaluates nicely.
f[3]
0.39004
It even graphs nicely.
Plot[f[x],{x,2,3}]
[cid:image0...@01CB8019.CA736910]
But it doesn't like me asking for a max...
FindMaximum[{f[a],2=A3a=A33},{a,3}]
The errors I get are the following
FindRoot::nlnum : The function value {1. -1. Cos[1. a]} is not a list of numbers with dimensions {1} at {x} = {1.}. ?
ReplaceAll::reps : {FindRoot[xSCos[a x],{x,1}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. ?
FindRoot::nlnum : The function value {1. -1. Cos[1. a]} is not a list of numbers with dimensions {1} at {x} = {1.}. ?
ReplaceAll::reps : {FindRoot[xSCos[a x],{x,1}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. ?
FindRoot::nlnum : The function value {1. -1. Cos[1. a]} is not a list of numbers with dimensions {1} at {x} = {1.}. ?
General::stop : Further output of FindRoot::nlnum will be suppressed during this calculation. ?
ReplaceAll::reps : {FindRoot[xSCos[a x],{x,1}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. ?
General::stop : Further output of ReplaceAll::reps will be suppressed during this calculation. ?
{-0.887727,{a=AE3.}}
f[a_?NumberQ] := x /.
Last[FindRoot[x == Cos[a x],
{x, .4}]]
f[3]
0.39004
Plot[f[x], {x, 2, 3}]
FindMaximum[{f[a], 2 <= a <= 3}, {a, 3}]
{0.514933, {a -> 2.}}
FindMaximum[{f[a], 2 <= a <= 3}, a]
{0.514933, {a -> 2.}}
NMaximize[{f[a], 2 <= a <= 3}, a]
{0.514933, {a -> 2.}}
I recommend that you use NumericQ rather than NumberQ
NumberQ /@ {Pi, E, GoldenRatio}
{False, False, False}
NumericQ /@ {Pi, E, GoldenRatio}
{True, True, True}
Bob Hanlon
---- "Van Peursem wrote:
=============