Ask Your Question
0

if statement not working

asked 2015-10-27 03:41:58 +0100

collabmath gravatar image

I am trying to make a sage interactive that switches between dx dy and dy dx. Yet, in my interactive when I press either I see no difference in the latex generated ie the order dx dy or dy dx does not chnage

def  interplay(order= permutations,function= input_box(sin(x*y)),lower_x_bound= input_box(0),upper_x_bound = input_box(1),lower_y_bound=input_box(0),upper_y_bound=input_box(1),showGraph = checkbox(default = False)):



    try:    

       if permutations == "dx dy":              
                 result = integral(integral(function,x,lower_x_bound,upper_x_bound),y,lower_y_bound,upper_y_bound)#function.integrate(x,lower_x_bound,upper_x_bound).integrate(y,lower_y_bound,upper_y_bound)

                 q="$\int_%s^{%s} \int_%s^%s %s \,dx\,dy = %s $" % (lower_y_bound, upper_y_bound,lower_x_bound,upper_x_bound,function,result)
                 # puts expressions inside latex
          else:
                result = integral(integral(function,y,lower_y_bound,upper_y_bound),y,lower_x_bound,upper_x_bound)
                #actually calculates integral
                q="$\int_%s^{%s} \int_%s^%s %s \,dy\,dx = %s $" % (lower_x_bound,upper_x_bound,lower_y_bound,upper_y_bound,function,result)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-10-27 10:32:39 +0100

stan gravatar image

Your example seems incomplete. Could you provide a working example and explain the desired behaviour?
Anyway, in your function definition, you define order=permutations, i.e. the internal variable 'order' has the standard value 'permutations', i.e. the value of 'permutations' when you define the function. If you change 'permutations' later on, it has no effect, unless you change the line from

if permutations == "dx dy":

to

if order == "dx dy":

If you then modify permutations and call:

permutations = "dx dy"
interplay(order= permutations)

the code in the if block should be executed and if you do something else such as

permutations = "blah"
interplay(order= permutations)

the code in the else block should be executed. Not sure if this answers your question, as I don't understand how the whole thing is supposed to work, so a working example would be nice.

edit flag offensive delete link more

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: 2015-10-27 03:41:58 +0100

Seen: 437 times

Last updated: Oct 27 '15