Trapezoid Rule in matlab?

I really need help on the attached document filling out the table at the bottom. I am totally lost on how to do this. I cant figure out the inside and outside forces. Help is desperately needed, I've been at this for a couple days trying to figure out this problem, but I just cant figure out where to start. I'll attach the code I have, don't know if it will help or not. I don't know how to calculate the forces needed to complete the table, so I calculated the force using the left and right sets of points that were given in vectors.
plot(x_left,y_hatch,x_right,y_hatch)
axis([-1 1 -2 0])
depth=input('Please enter how far the top of the sumbarine is below water')
dy=depth-y_hatch
P=101353
p=1027
g=9.81
y=depth
x1=x_left(4)-x_left(2)
x2=x_right(3)-x_right(1)
for k=1:length(y_hatch)
Area_left(k)=x_left(k)*dy(k)
Area_right(k)=x_right(k)*dy(k)
Left_Force(k)=(P+p*g*y)*(x_left(k)*dy(k))
Right_Force(k)=(P+p*g*y)*(x_right(k)*dy(k))
TotalForce=((P + p*g*y)*((x1+x2 ))/(2*dy(k)))
end

Answers (1)

Star Strider
Star Strider on 11 Mar 2016
I don’t have the data for the door so I can’t run your code. Besides, this is far from my areas of expertise.
When I looked at the PDF and then your code, I noticed some problems:
  1. The dy variable is a constant. It does not change, but ‘y_hatch’ does (or so I assume). Also, you define ‘dy’ as a scalar (appropriately), the index into it in your loop (inappropriately). That likely throws an error.
  2. It seems to me that depth incremented down the length of hatch never changes, but likely should in the loop, probably as ‘depth+y_hatch(k)’. Consider replacing ‘dy(k)’ with ‘depth+y_hatch(k)+dy’ to account for ‘dy’ as well, or something similar.
  3. Also, there should be an integer number of ‘dy’ slices down the length of the door. The value of ‘dy’ needs to be the length of the hatch divided by the number of elements in the vectors describing it down its length. So if the length (height) is one metre, and the number of elements in the vector describing it is 100, ‘dy’ should be a constant 0.01 metre.
Go through your code and be sure it makes sense. Draw pictures to help you understand what you need to do, and use flow-charts for your code if they will help.
I can’t really add more to this, so I won’t.

2 Comments

I see what you're saying. Im just still confused on how to calculate the inside and outside forces. Sorry for not including the data for the door, I now attached that file. It is named Sumbarine_Hatch(2). I will look over what you said above. Thanks.
My pleasure.

Sign in to comment.

Asked:

on 11 Mar 2016

Commented:

on 11 Mar 2016

Community Treasure Hunt

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

Start Hunting!