Ask Your Question
0

Max return a partial false result

asked 2022-11-21 08:01:19 +0100

Cyrille gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-11-21 08:10:05 +0100

updated 2022-11-21 17:55:50 +0100

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.

edit flag offensive delete link more

Comments

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

Cyrille gravatar imageCyrille ( 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

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

In the plot you can recognize the lines and their zeros

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

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

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

See my edit.

John Palmieri gravatar imageJohn Palmieri ( 2022-11-21 17:56:00 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-11-21 08:01:19 +0100

Seen: 196 times

Last updated: Nov 21 '22