An open channel has a trapezoidal cross-section as shown in the figure. If all the sides have an equal length of 2 m, find the angle x that maximizes the cross-sectional area using: a) A Graphical Approach b) The Golden Section Search (with es=0.05)

1 view (last 30 days)
"An open channel has a trapezoidal cross-section as shown in the figure. If all the sides have an equal length of 2 m, find the angle x that maximizes the cross-sectional area using: a) A Graphical Approach b) The Golden Section Search (with es=0.05)"
I did this :
xl=0;
xu=180;
ea=10;
es=0.05;
f=@(x) 4.*sind(x)+4.*cosd(x).*sind(x);
d=(1.61803-1)*(xu-xl);
x1=xl+d;
x2=xu-d;
for i=0;
f(x2); f(x1);
if f(x2) > f(x1)
xopt= x1;
x1 = x2;
d=(1.61803-1)*(xopt-xl);
x2=xopt-d;
end
if f(x1)< f(x2)
xopt = x2;
x2=x1;
d=(1.61803-1)*(xu-xopt);
x1=xopt+d;
end
if ea>es
ea = (2 - 1.61803) * abs((xu - xl) / xopt)*100 ;
end
end
i=1+i
xopt
What is the problem with my code?

Answers (1)

Image Analyst
Image Analyst on 3 Dec 2016
You know the height is y = 2 * sin(theta).
The rectangular center's area is 2 * y.
The Triangle's base is x = 2 * cos(theta);
The area of each triangular side is (1/2)*x*y, and there are two of them,
so the total area = 2*y+x*y
Substitute x and y for the formula in terms of theta. Then make theta equal
theta = linspace(0, pi/2, 1000);
Then plot a graph of area as a function of theta. You can get the max area with the max() function. Be sure to use both output arguments of max() so you can use the index to get the theta where the max occurs.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!