Assignment : Solving Area under curves and Centroid of that region in sagemath

The assigned question as revision to all curve tracing that i done in sagemath was this :

Along with height of line parallel to x-axis i.e.  h=(k*fck)/g where k=0.67,fck=20 and g=1.5

Here is the sage code for it. All statements are given with comments . No need to explain more.

#### variable declaration: #######
var('x,x1,x2,y1,y2,k,fck,g,c,y,ax1,ax2,ax,ay1,ay2,ay,total_area,x_cg_of_parabola,y_cg_of_parabola,x_cg_of_rect,y_cg_of_rect,centroid_x,y,centroid_y')
k=0.67
fck=20
x1=0.002
g=1.5
x2=0.0035
y1=0
h=(k*fck)/g
y2=h
#### Line parallel to x-axis ######
line1=h
a=(2*h)/x1
b=(h/x1^2)
c=x2-x1

## Parabola's Equation:

f(x)= a*x -b*x^2

## Area under Parabola

area1=integrate(f,x,0,x1)

## Area under line parallel to x-axis

area2=integrate(line1,x,x1,x2)

## Total Area

total_area=area1+area2

## Using Formula : Centroid = Moment/Area where Moment = distance*area

x_cg_of_parabola=(1/area1)*integrate(x*f(x),x,0,x1)
print "x cg of parabola",x_cg_of_parabola

#### , is used to concatenate in sage or we can say cascading in c plus plus language ####

y_cg_of_parabola=(1/(area1*2))*integrate((f(x))^2,x,0,x1)
print "y cg of parabola",y_cg_of_parabola
print "(",x_cg_of_parabola,",",y_cg_of_parabola,")"
x_cg_of_rect=(1/area2)*integrate(y2*x,x,x1,x2)
print "x cg of rect",x_cg_of_rect

y_cg_of_rect=(1/(area2*2))*(h^2)*integrate(1,x,x1,x2) 
print "y cg of rect",y_cg_of_rect
ax1=x_cg_of_parabola*area1
ax2=x_cg_of_rect*area2
ax=ax1+ax2
ay1=y_cg_of_parabola*area1
ay2=y_cg_of_rect*area2
ay=ay1+ay2
centroid_x=ax/total_area
print "centroid x:",centroid_x
centroid_y=ay/total_area
print "centroid y",centroid_y

### Plotting of given problem######

    ### points showing centriod of area under parabola, area under line and centroid of combined region############

p=point((x_cg_of_parabola,y_cg_of_parabola),color='red',pointsize=100)
p+=point((x_cg_of_rect,y_cg_of_rect),color ='red', pointsize=100)
p+=point((centroid_x,centroid_y),color='red',pointsize=100)

    ##Ploting parabola and line respectively###
p+=plot(f,(x,0,x1),color='blue',fill=True)
p+=plot(line1,x1,x2,color='red',fill=True)
p.show() ### using imagemagick

Output Graph :

 

If need assistance for center of gravity, you can refer these videos:

Thats all.

Advertisements

About Priyanka Kapoor

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

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