Area Under Curve in Sage

Q:- Find the area between the curves : x=1-y^2 and x=y^2-1

Ans:- Lets say the following code is in file named as define1.sage. Go to terminal and type sage. You will get sage prompt if sage is installed on PC. type:

attach define1.sage 
var('y')
b=1-y^2
r=y^2-1
e=solve(b==r,y)
print "Points of intersection"
print e
d=integrate(b-r,-1,1)
print "Area under two curves is:"
print d
c=plot(b,(y,-1,1),color='blue')
c+=plot(r,(y,-1,1),color='red')
L = [[-1 + i/10, b(-1 + i/10)] for i in range(21)]
M = [[-1 + i/10, r(-1 + i/10)] for i in range(21)]
pfill = polygon(L+M, color='yellow')
show(c+pfill)
 

Output :

Points of intersection

[
x== -1,
x== 1
]

Area under two curves:

8/3

Note: If on running program image is not provoked then replace show(c+pfill) with two lines q=c+pfill and q.save(‘filename.png’). With this image gets saved in home folder with name filename.png.

Q:- Find the area between curves: y=4x-x^2  and       y=x

var('x')
 b=4*x-x^2
 r=x
 e=solve(b==r,x)
 print e
 d=integrate(b-r,0,3)
 print d
 c=plot(b,(x,0,3),color='blue')
 c+=plot(r,(x,0,3),color='red')
 show(c,aspect_ratio=1)

Output:

[
y == 0,
y == 3
]
9/2

Q:- Find the area between curve and x-ais, where curve is :y=x^2.

Ans:-

a = -1; b = 1
f = lambda x: x^2
d=integrate(f(x),a,b)
print "Area under curve and x-axis is:"
print d
Lb = [[b,f(b)], [b,0], [a,0], [a,f(a)]]
Lf = [[i/20, f(i/20)] for i in xrange(20*a, 20*b+1)]
P = polygon(Lf+Lb, rgbcolor=(0.2,0.8,0))
Q = plot(f(x), x, a-0.5, b+0.5)
show(P+Q)

Output:

Area under curve and x-axis is:

2/3

 

 

 

 

Q:- Find the area between two curves: y=0 and y=3*(x^3-x)

Ans:-

var('x')
b=0
r=3*(x^3-x)
e=solve(b==r,x) 
print "Points of intersection:"
print e
d=integrate(r-b,-1,0)+integrate(b-r,0,1)
print "Area between curves is:"
print d
c=plot(b,(x,-1,1),color='blue')
c+=plot(r,(x,-1,1),color='red')
show(c,aspect_ratio=1)

Output:

Points of intersection:

[
x == -1,
x == 1,
x == 0
]
Area between curves is:
3/2

Q:- Find the area between curves y=x^2 and y=x^3

Ans:-

var('x')
b=x^2
r=x^3
e=solve(b==r,x) 
print "Points of intersection:"
print e
d=integrate(b-r,0,1)
print "Area between curves is:"
print d
text("x^2",(0.5,0.5))
c=plot(b,(x,-1,1),color='blue')
c+=plot(r,(x,-1,1),color='red')
t3 = text("y=x^2" ,(0.5,0.5), rgbcolor=(0,0,1))
show(c+t3,aspect_ratio=1)

Output:

Points of intersection:

[
x == 0,
x == 1
]
Area between curves is
1/12

Advertisements

About Priyanka Kapoor

Simple, Hardworking & friendly.....
This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Area Under Curve in Sage

  1. Mandi says:

    This is a comment to the webmaster. I came to your “Area Under Curve in Sage | priyankacool10” page via Google but it was hard to find as you were not on the first page of search results. I see you could have more traffic because there are not many comments on your site yet. I have found a website which offers to dramatically increase your rankings and traffic to your website: http://www.linklegends.com/free-trial. I managed to get close to 1000 visitors/day using their services, you could also get lot more targeted traffic from search engines than you have now. Their free trial and brought significantly more visitors to my site. Hope this helps 🙂 Take care.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s