Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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")
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

3030302776, 978-3030302771

More Books

Students also viewed these Databases questions