Question: Can somebody help me what is the error in this code? % Define the symbolic Variable x syms x; % Enter the upper and lower

Can somebody help me what is the error in this code?
%Define the symbolic Variable x
syms x;
%Enter the upper and lower functions as y1(x) and y2(x), respectively.
k=randi(20,1);
y1(x)= k-x^2;
y2(x)= x^2+x-k;
%Solve the point of intersections. Save the array of solutions as roots.
roots = solve(y1== y2, x);
%Save the lower value as x1 and the higher limit as x2. Use min and max to compare the roots for lower and upper limit.
%Convert the roots from symbolic constants to double.
x1= min(roots);
x2= max(roots);
x1= double(x1);
x2= double(x2);
%Find the points of intersection between the twop curves. Set it as an array P1=[x, y]
P1=[x1, y1(x1)];
P2=[x2, y2(x2)];
%Set the difference of the upper minus the lower function as I. Use absolute value function to ensure positive area
I = abs(y1- y2);
%Use the integration to the find the area bounded by the two curves at the computed boundary.
Area = int(I, x, x1, x2);
%Determine the moment along y axis.
My = int(x * I, x, x1, x2);
%Determine the centroidal element ybar by finding the midoint of the lower and upper curves.
ybar = double(My / Area);
%Determine the moment along y axis.
Mx =int(ybar*I, x, x1, x2);
%Find the centroidal elements xc,yc by dividing the Moments by the Area. Convert the answer as Doubles
xc = double(Mx / Area);
yc = double(ybar);
%Combine the centroidal elements as Centroid as an array of element xc and yc
Centroid =[xc, yc];
%Set the graphing margin allowance to 1
margin =1;
%Graphing of the regions
ezplot(y1,[x1-margin, x2+margin]);
hold on;
ezplot(y2,[x1-margin,x2+margin]);
grid on;
k= linspace(x1,x2);
k2=[k,fliplr(k)];
inBetween =[y1(k), fliplr(y2(k))];
fill(k2, inBetween, 'y');
plot(x1,y1(x1),"r*");
plot(x2,y1(x2),"r*");
title ("Centroid of Plane Region")
plot(xc,yc,"bo")
 Can somebody help me what is the error in this code?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!