0
$\begingroup$

I am trying to define a function $H(s)$ in Mathematica, but the only restrictions/information on this function are that it is a concave and increasing in $s$, which is defined over the interval $[0,S_{\text{max}}]$. Further, $H(s=0)=0$ and $H(s>0)=h>0$. Since the exact form isn't specified, I'm not sure how to use the := command here.

$\endgroup$
4
  • 1
    $\begingroup$ There isn't a way to do this without assuming some kind of form. I think it would help to know why you needed to define such an abstract function. $\endgroup$
    – flinty
    Jun 12, 2021 at 10:30
  • 2
    $\begingroup$ This looks like an XY problem to me. It is not answerable unless you explain what you are actually trying to do. $\endgroup$
    – Szabolcs
    Jun 12, 2021 at 12:06
  • $\begingroup$ Mathematica is an expression rewriting system. := simply tells it to rewrite anything that matches the left hand side using the right hand side. $\endgroup$
    – John Doty
    Jun 12, 2021 at 13:22
  • $\begingroup$ Is h a constant? If yes, H is a step function: H= Piecewise[{{h, # > 0}}, 0] & where h is the constant value. $\endgroup$ Jun 12, 2021 at 19:53

1 Answer 1

3
$\begingroup$

Perhaps something like this?

H[0] = 0;
H[x_] := ConditionalExpression[h[x], h[x] > 0 && x > 0];
(* Alternatively, you can do *)
H[x_] := ConditionalExpression[#, # > 0 && x > 0] &@h[x]; 

Let's try this with:

h[x_] = (x + 5)(x - 5);

There are 5 possible cases to test:

$H(s = 0)$

H[0] (* Outputs 0 *)

$H(s < 0) = h > 0$

H[-6] (* Outputs Undefined *)

$H(s < 0) = h \leq 0$

H[-1] (* Outputs Undefined *)
H[-5] (* Outputs Undefined *)

$H(s > 0) = h \leq 0$

H[1] (* Outputs Undefined *)
H[5] (* Outputs Undefined *)

$H(s > 0) = h > 0$

H[6] (* Outputs 11 *)

Unknown $h(x)$

If you don't have a definition for $h(x)$, you could define an additional function which simplifies the conditional statement depending on the constraints on $h(x)$ by using Assumptions:

f[x_] := Simplify[H[x]];
f[x_, ineq_] := Simplify[H[x], Assumptions -> {ineq /. h -> h[x]}];

Test cases:

$H(s = 0)$

f[0] (* Outputs 0 *)
f[7] (* Outputs unsimplified conditional expression: ConditionalExpression[h[7], h[7] > 0] *)

$H(s < 0) = h > 0$

f[-6, h > 0] (* Outputs Undefined *)
f[-6, h > 7] (* Outputs Undefined *)

$H(s < 0) = h \leq 0$

f[-1, h <= 0] (* Outputs Undefined *)
f[-5, h <= 0]  (* Outputs Undefined *)
f[-5, -3 < h < -1]  (* Outputs Undefined *)

$H(s > 0) = h \leq 0$

f[1, h <= 0]  (* Outputs Undefined *)
f[5, h <= 0] (* Outputs Undefined *)
f[5, -3 < h < -1] (* Outputs Undefined *)

$H(s > 0) = h > 0$

f[6, h > 0] (* Outputs h[6] *)
f[6, h > 7] (* Outputs h[6] *)
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.