# Max return a partial false result

Suppose I have four (may be more) linear functions say :

f0(x) = -3 x
f1(x) = -3 x + 1
f2(x) = -6 x + 2
f3(x) = -9 x + 3


for $x \in [0, 1]$. They are easy to plot

plot((f0(x),f1(x),f2(x),f3(x)),(x,0,1),color=['red','blue','green','cyan'])


So one can see that for $x \in [0,1/3[$ $\max{f0(x),f1(x),f2(x),f3(x)} = f3(x)$ and for $x \in ]1/3, 1]$, $\max{f0(x),f1(x),f2(x),f3(x)} = f1(x)$.

But

max(f0(x),f1(x),f2(x),f3(x))


return only $f1(x)$. How to correct this result ?

edit retag close merge delete

Sort by ยป oldest newest most voted

Try max_symbolic instead of max, and see https://doc.sagemath.org/html/en/refe... for documentation.

Edit: if you want a function, do

g(x) = max_symbolic(f0(x), f1(x), f2(x), f3(x))


Then you can compute g(3), etc.

more

I do not understand. The result of max_symbolic is simply the question. Not a function linear by part.

( 2022-11-21 15:15:01 +0100 )edit

plot(max_symbolic(f0(x),f1(x),f2(x),f3(x)),(x,0,1))

solves the problem graphically

( 2022-11-21 16:17:07 +0100 )edit

In the plot you can recognize the lines and their zeros

( 2022-11-21 16:54:18 +0100 )edit

It's nice but I was hopping the return of a function

( 2022-11-21 17:48:11 +0100 )edit

See my edit.

( 2022-11-21 17:56:00 +0100 )edit