Ask Your Question
1

Generating functions and plotting them with different colors

asked 2012-09-15 07:58:01 +0200

Flavius gravatar image

updated 2012-09-15 08:02:15 +0200

Let's say I have the logistic function

f(x) = a / (1 + b*e^(-(x-c)/d))

For a, the value will likely not change, it stays fixed at 1. b will remain in the meanwhile at 0.2, but I would like to plot all other variants of the function for x in the interval 0, 21 for different values of c and d in different colors (like color lerp).

Like, for all combinations of c,d in [0.2,0.4,0.6,0.8,1.0,1.2]

How to achieve this in sage 5.2 and python? I've tried simply using a python function that returns a "sage function" but it doesn't work.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2012-09-15 09:32:23 +0200

achrzesz gravatar image

updated 2012-09-16 04:56:14 +0200

a=1.
b=0.2 
f(c,d)= a / (1 + b*e^(-(x-c)/d))  
sum([plot(f(c,d),[x,0,5],color=hue((c+10*d)/3)) for c in srange(0.2,1.3,.2) for d in srange(0.2,1.3,.2)]).show()

#It seems that 36 curves is too many but I hope it can help to experiment

Or using the suggestion by kcrisman

a=1.
b=0.2 
f(c,d)=a/(1+b*e^(-(x-c)/d)) 
curves=[f(c,d) for c in srange(0.2,1.3,.2) for d in srange(0.2,1.3,.2)]
l=len(curves)
colors=rainbow(l)                                            
sum(plot(curves[k],[x,0,5],color=colors[k]) for k in range(l)).show()
edit flag offensive delete link more

Comments

The `rainbow(n)` function may also be useful here, depending on what your goal is.

kcrisman gravatar imagekcrisman ( 2012-09-15 23:56:55 +0200 )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

Stats

Asked: 2012-09-15 07:58:01 +0200

Seen: 621 times

Last updated: Sep 16 '12