Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
0

Max return a partial false result

asked 2 years ago

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[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[0,1/3[ maxf0(x),f1(x),f2(x),f3(x)=f3(x) and for x]1/3,1], maxf0(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 ?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 2 years ago

updated 2 years ago

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.

Preview: (hide)
link

Comments

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

Cyrille gravatar imageCyrille ( 2 years ago )

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

solves the problem graphically

achrzesz gravatar imageachrzesz ( 2 years ago )

In the plot you can recognize the lines and their zeros

achrzesz gravatar imageachrzesz ( 2 years ago )

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

Cyrille gravatar imageCyrille ( 2 years ago )

See my edit.

John Palmieri gravatar imageJohn Palmieri ( 2 years ago )

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: 2 years ago

Seen: 204 times

Last updated: Nov 21 '22