TransWikia.com

How to find the max of two functions?

Mathematica Asked on July 26, 2021

Suppose I have a parametric function like f(v)=max{v-x,-y} where 0<=v<v_max, and x>=0, y>=0. I want to find simplify f(v) as follows.

f(v)=max{v-x,y}= -y if v<x-y, v-x if v>=x-y
I use the following code, but the problem is that if x-y<0, then the condition -y if v<x-y will not be true.

f[v_, x_] := v - x;
g[y_] := -y;
h[v_, x_, y_] :=  f[v, x]*Boole[f[v, x] >= g[y]] + g[y] (1 - Boole[f[v, x] >= g[y]]) // Simplify;

Is it possible to explicitly have the conditions that are not listed in True?

2 Answers

Would an explicit Piecewise do what you need?

h[v_, x_, y_] = 
  Piecewise[{{f[v, x], f[v, x] >= g[y]},
             {g[y],    f[v, x] < g[y]}}]

$$ left{ begin{array}{ll} v-x & text{if }v-xge -y -y & text{if }v-x< -y 0 & text{if True} end{array} right. $$

Please note the immediate assignment. It makes little sense to have a Simplify statement in a delayed assignment.

Answered by Roman on July 26, 2021

Clear["Global`*"]

f[v_, x_] := v - x;
g[y_] := -y;
h[v_, x_, y_] := 
  f[v, x]*Boole[f[v, x] >= g[y]] + g[y] (1 - Boole[f[v, x] >= g[y]]) // 
   Simplify;

h[v, x, y]

enter image description here

The condition represented by True is

Not@h[v, x, y][[1, 1, -1]]

(* v + y < x *)

For multiple conditions,

integration = 
 Assuming[vmax > 0, Integrate[h[v, x, y], {v, 0, vmax}] // Simplify]

enter image description here

The condition represented by True is

ConditionalExpression[Simplify@Not[Or @@ integration[[1, All, -1]]], 
 vmax > 0]

enter image description here

Answered by Bob Hanlon on July 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP