Ask Your Question
0

Double Integration not working

asked 2015-10-27 22:01:32 +0100

collabmath gravatar image

I am making a double integral interactive. However instead of giving my result for sin(xy) from x = 0 to x = 1 and y= 0 to y = 1 it gives integrate(-cos(2y)/y + 1/y,y,0,1).

 from sage.plot.plot3d.shapes import Box
x,y = var('x,y')
html("<h1>Double Integrator<h1>")
#permutations = ["dx dy","dy dx"]
@interact

def  interplay(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),dydx = checkbox(default = False)):



    try:    

          if dydx==False :              
                 prev = integral(function,x,lower_x_bound,upper_x_bound)
                 result = integral(prev,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)


         #if type(lower_x_bound)!=float or type(upper_x_bound)!=float or type(lower_y_bound)!= float or type(upper_y_bound)!= float :


          html("%s" %q)
    except:
        print(" "+"Please enter better bounds")





     #show(result)
html("<p> Created by Hans Gundlach </p>")
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-10-27 22:37:33 +0100

fidbc gravatar image

Double integration is working. If you would like a numeric approximation you can call the n function with your last integral as an argument. See code below (modified from above).

from sage.plot.plot3d.shapes import Box
x,y = var('x,y')

@interact
def  interplay(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),dydx = checkbox(default = False)):
    if dydx==False :              
        prev = integral(function,x,lower_x_bound,upper_x_bound)
        result = n(integral(prev,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)
    else:
        result = n(integral(integral(function,y,lower_y_bound,upper_y_bound),x,lower_x_bound,upper_x_bound))
        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)
    html("%s" %q)

I think there was a typo in your original code. You integrate twice wrt y when dydx is True.

edit flag offensive delete link more

Comments

Sorry I specifically want the integrator to give the symbolic double integral as well as the numerical one

collabmath gravatar imagecollabmath ( 2015-10-29 03:06:09 +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: 2015-10-27 22:01:32 +0100

Seen: 945 times

Last updated: Oct 27 '15