Can someone please explain why the variables I, Area, Mx, My has an incorrect values? Thanks!
Mostrar comentarios más antiguos
%Define the symbolic Variable x
syms x
%Enter the upper and lower functions as y1(x) and y2(x), respectively.
y1(x) = x^2-5;
k=randi(20,1);
y2(x) = k*x;
%Solve the point of intersections. Save the array of solutions as roots.
roots = solve(y1(x) == 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 = double(min(roots));
x2 = double(max(roots));
%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 = symfun(int(y1(x) - y2(x), x, x1, x2), x);
%Use the integration to the find the area bounded by the two curves at the computed boundary.
Area = int(y1(x) - y2(x), x, x1, x2);
%Determine the moment along y axis.
My = int((1/2)*(y1(x)^2 - y2(x)^2), x, x1, x2);
%Determine the centroidal element ybar by finding the midoint of the lower and upper curves.
ybar = double(My/I);
%Determine the moment along y axis.
Mx = int(x*(y1(x) - y2(x)), x, x1, x2);
%Find the centroidal elements xc,yc by dividing the Moments by the Area. Convert the answer as Doubles
xc = double(Mx/I);
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")
3 comentarios
Torsten
el 5 de Abr. de 2023
And which values should the variables have ?
Gabriel Enzo
el 10 de Abr. de 2023
Dyuman Joshi
el 10 de Abr. de 2023
There does not seem to be any error in your code.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

