Assignment: Type a symbolic code (MATLAB) to verify one of the centroids and areas given in the “Centroids of common shapes of areas and lines” table:


  1. Takes three points and solves for the coefficients of a quadratic equation through the three points.
  2. Search Matlab documentation for “Systems of Linear Equations” for methods to solve systems of equations.
  3. Integrate this quadratic equation between two given x values.
  4. Vertical strips are used for the integration
  5. Integrating x times the quadratic equation to get the first moment of area with respect to the y axis.
  6. Compute the x centroid of the area under the curve.
  7. Integrating y/2 times the quadratic equation to get the first moment of area with respect to the x axis.
  8. Compute the y centroid of the area under the curve.
  9. Graph the area under the curve, the three given points and the x location of the centroid.


%% This script calculates a quadratic function and it’s x-centroid

% The quadratic function that goes through the three points given

% is solved.

% The quadratic equation is then integrated between two given x values

% along with the integral of x times the function. These integrals

% are then used to calculate the X centroid of the area between

% the function and the x-axis.

% Givens:

% Enter three points as P = [ x1,y1 ; x2,y2; x3,y3 ];

P = [ -1, 2 ; 0, pi ; 3, 1 ];

% Enter the end points for integration, x0 and x1

x0 = 0;

x1 = 3;

% Solution:

% Define symbolic variables

syms x a b c

% Define three equations for a quadratic at the three given points

X = P(:,1); % extract the given x values from P

Y = P(:,2); % extract the given y values from P

Eq = Y == a .* X .* X + b .* X + c; % Eq is an array of equations

% Note the ‘==’ makes an equation, left side equals right side

% Solve for the a,b and c coeficients

sol = solve(Eq,[a,b,c]); % ‘solve’ will solve a system of equations

% The solution is a matlab structure where each variables solution/s

% are accessed with sol.a, sol.b or sol.c

% Define the quadratic equation using the constants

quad = @(x) sol.a .* x .^ 2 + sol.b .* x + sol.c;

% note use of .* and .^ to operate on coresponding array elements

% the @(x) defines a function that takes x as an independent variable

% It is used as quad(independent variable)

% Integrate the quadratic equation

Area = int(quad,x,x0,x1);

% Integrate the quadratic equation times x

XArea = int(x*quad,x,x0,x1);

% Solve for the centroid

xbar = XArea/Area;

% Answer :

% Print the quadratic equation

fprintf(“The quadratic equation through the three given points is : “);

% make a text of the equation to use in the plot also

equationText = sprintf(“y = %.3g x^2 %+.3g x %+.3g”,sol.a,sol.b,sol.c);

fprintf(“%s “,equationText);

% When using a script the ‘ ‘ adds a new line

fprintf(“The area between the function and the x axis is %.3g “,Area);

fprintf(“The x value of the areas centroid is %.3g”,xbar);

% Plot the quadratic equation

% Calculate variables to plot between x0 and x1

xplot = linspace(x0,x1,50); % array of x values to plot

yplot = quad(xplot); % array of y values to plot

% Plot the function shading the area between the function and

% the x axis

plot(xplot, yplot,’-‘,”LineWidth”,3);

% Give the plot a title

title(“Quadratic Equation through three points”);

% Label the axes ‘x’ and ‘y’



% prepare the plot for further additions

hold on;

% Shade the area below the curve


% Add the three given points to the graph


% Add a vertical line at the x centroid

yl = ylim(); % get the y limits

xb = [xbar,xbar]; % set to x values for the line

plot(xb,yl,’–‘); % graph the line

text(xbar,ycenter/2,’Centroid ‘,’HorizontalAlignment’,’right’); % add


% Add the quadratic equation to the center of the graph

xcenter = (x0+x1)/2; % the center of the integral

ycenter = (max(yplot) + min(yplot))/2; % the center of the yplot values

text(xcenter,ycenter, equationText,…


% end the graph

hold off;


  • Attachment 1
  • Attachment 2
"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"