Group Abstract Group Abstract

Message Boards Message Boards

0
|
89 Views
|
5 Replies
|
7 Total Likes
View groups...
Share
Share this post:

Condensing the last line of monotonicity-check code

Posted 5 days ago
POSTED BY: Bill Blair
5 Replies

Why not write a function "funcNegPos[f_, x_] :=.." that returns the intervals where f is negative (resp. positive), and use that on f and g? Sacrifice concision for clarity. It makes programming easier in the long run.

That said, here's another short way, similar to Gianluca's but using Outer[] on a function instead of Table[] on a symbolic formula. (They are roughly equivalent, mutatis mutandis, ignoring occasional performance differences.)

Outer[Reduce[{#2[#1[x], 0]}, x, Reals] &, {f, g}, {Less, Greater}]
POSTED BY: Michael Rogers
Posted 4 days ago
POSTED BY: Bill Blair

The domains are not independent of the functions. Each function needs to be joined with its domain and not in a separate, independent list. To anticipate further addenda, here is the general framework for using Outer[], which in this problem should have only two list arguments, one containing the data for each function and one containing the comparators:

Outer[reductionFunction, functionDataObjects, {Less, Greater}]

reductionFunction[fnData, comp] should be a function with two arguments, the function data and the comparator.

Outer[] produces all combinations of elements taking one from each list from the second argument on. Compare two lists to three lists:

Outer[R, {f, g}, {c1, c2}]
(*
{ {R[f, c1], R[f, c2]},  {R[g, c1], R[g, c2]} }
*)

Outer[R, {f, g}, {df, dg}, {c1, c2}]
(*
{{ {R[f, df, c1], R[f, df, c2]},  {R[f, dg, c1], R[f, dg, c2]} },
 { {R[g, df, c1], R[g, df, c2]},  {R[g, dg, c1], R[g, dg, c2]} }}
*)
POSTED BY: Michael Rogers
Posted 4 days ago
f[x_] = (3 x - 2)/(7 x - 6);
g[x_] = 7 - Log[x];
fd = FunctionDomain[f[x], x];
gd = FunctionDomain[g[x], x];


functionData = {<|"fn" -> f, "dom" -> fd|>, <|"fn" -> g, "dom" -> gd|>};


reductionFunction[fnData_, comp_] := 
  Reduce[{fnData["fn"][x]~comp~0, fnData["dom"]}, x, Reals];


Outer[reductionFunction, functionData, {Less, Greater}]
POSTED BY: Bill Blair

Here is an attempt:

Table[{rel[func, 0], "\[DoubleLeftRightArrow]", 
  Reduce[rel[func[x], 0], x]},
 {func, {f, g}}, {rel, {Less, Greater}}]
Flatten[%, 1] // TableForm
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard