To calculate the centroid of an area bounded by a line and a parabola in MATLAB, we need to follow these steps:
main.m368 chars10 lines
roots
function.main.m226 chars6 lines
main.m219 chars4 lines
Here, we have used the quadgk
function to numerically integrate the functions that describe the areas above and below the line. The limits of integration are the x-coordinates of the intersection points.
x_c = (1/A) * (integral of x * f(x) dx over the region)
where A is the total area of the region and f(x) is the height of the region at x. In MATLAB, we can do this using the quadgk
function again, where we replace the f(x) with the x distance from the y-axis to the curve at x.
main.m424 chars6 lines
y_c = (1/A) * (integral of (1/2) * [f(x)]^2 dx over the region)
In MATLAB, we can do this using the quadgk
function one last time.
main.m385 chars8 lines
gistlibby LogSnag