Simpson's rule with changing volumes

Click For Summary
SUMMARY

The discussion focuses on calculating the buoyancy force of a lifeboat using Simpson's rule for numerical integration. The user, Noel, is attempting to compute the immersed volume of the lifeboat, which is essential for determining buoyancy. The provided MATLAB code attempts to implement Simpson's 1/3 rule but encounters issues with loop structures and volume calculations. Key insights include the need to evaluate the volume at each time step as the lifeboat enters the water and the importance of correctly structuring loops to avoid infinite iterations.

PREREQUISITES
  • Understanding of buoyancy principles and the buoyancy force equation
  • Familiarity with numerical integration techniques, specifically Simpson's rule
  • Basic knowledge of MATLAB programming, including loop structures and function definitions
  • Concept of time-stepping in simulations for dynamic systems
NEXT STEPS
  • Review MATLAB's numerical integration functions, such as integral and trapz
  • Learn about MATLAB loop structures and best practices for avoiding infinite loops
  • Explore the concept of dynamic simulations in MATLAB, focusing on time-dependent volume calculations
  • Investigate how to visualize simulation results in MATLAB for better understanding of buoyancy changes
USEFUL FOR

Students and professionals in engineering, particularly those involved in fluid dynamics, simulation modeling, and MATLAB programming. This discussion is especially beneficial for those working on buoyancy-related calculations in marine engineering projects.

noelll
Messages
13
Reaction score
0
Hi there,

Homework Statement


I am doing a simulation of a free-fall lifeboat trajectory into the ocean and there is a part where i need to get the volume of the lifeboat to obtain its buoyancy force.

Buoyancy force is proportional to the immersed volume of the body and this volume can be obtain by integrating the immersed cross-section area along the length of the boat(I am using Simpson's rule 1/3 for this).

2. Homework Equations

Buoyancy force = Density*gravity*volume

Question i would like to ask, do i need to find the volume in a time-step manner, currently the ideal i have in mind is at each meter of the lifeboat length i will obtain a cross-section and after reaching the end of the lifeboat length which is 8.5 m i add up all the cross-section area? however i do not know how to do it.

The Attempt at a Solution


i tried doing the simpson's rule. But i could only get a single number.
Code:
%INPUTS
L      = 0;   %lower limit
U      = 8.5; % upper limit
n      = 40;  % number of segments
Length = 1;
Breath = 3;
Height = 2.3;
density= 1.025;
g      = 9.81;

func = @(x) (Breath * Height);
h = (U-L)/n;

st4 = 0;
st2 = 0;

for i = 2:h:n
    st4 = st4 + 4*func(i);
end

for i = 3:h:n
    st2 = st2 + 2*func(n);
end

buoyancy_force = (density*g)*(h/3*(func(1)+st4+st2+func(i)));
  
disp (buoyancy_force)
fprintf('step %.3f\n',i);
disp (st4)
disp (st2)

I hope anybody out there could help me, really need your help, thank you so much!
Best Regards,
Noel
 
Last edited:
Physics news on Phys.org
noelll said:
Hi there,

Homework Statement


I am doing a simulation of a free-fall lifeboat trajectory into the ocean and there is a part where i need to get the volume of the lifeboat to obtain its buoyancy force.

Buoyancy force is proportional to the immersed volume of the body and this volume can be obtain by integrating the immersed cross-section area along the length of the boat(I am using Simpson's rule 1/3 for this).

2. Homework Equations

Buoyancy force = Density*gravity*volume

Question i would like to ask, do i need to find the volume in a time-step manner, currently the ideal i have in mind is at each meter of the lifeboat length i will obtain a cross-section and after reaching the end of the lifeboat length which is 8.5 m i add up all the cross-section area? however i do not know how to do it.

The Attempt at a Solution


i tried doing the simpson's rule. But i could only get a single number.
Code:
%INPUTS
L      = 0;   %lower limit
U      = 8.5; % upper limit
n      = 40;  % number of segments
Length = 1;
Breath = 3;
Height = 2.3;
density= 1.025;
g      = 9.81;

func = @(x) (Breath * Height);
h = (U-L)/n;

st4 = 0;
st2 = 0;

for i = 2:h:n
    st4 = st4 + 4*func(i);
end

for i = 3:h:n
    st2 = st2 + 2*func(n);
end

buoyancy_force = (density*g)*(h/3*(func(1)+st4+st2+func(i)));
 
disp (buoyancy_force)
fprintf('step %.3f\n',i);
disp (st4)
disp (st2)

I hope anybody out there could help me, really need your help, thank you so much!
Best Regards,
Noel
Well, volume is a single number. You are calculating the area under the curve of cross-sectional areas for the hull of the lifeboat, and this area is numerically equal to the volume.

If the immersed volume of the lifeboat is changing in time, then you'll have to calculate a new volume with each time step, assuming you can determine the shape of the cross sections which compose this volume at the corresponding time.
 
SteamKing said:
Well, volume is a single number. You are calculating the area under the curve of cross-sectional areas for the hull of the lifeboat, and this area is numerically equal to the volume.

If the immersed volume of the lifeboat is changing in time, then you'll have to calculate a new volume with each time step, assuming you can determine the shape of the cross sections which compose this volume at the corresponding time.

Hi,
Thank you so much for your reply,
yes the immersed volume of the lifeboat is changing as it enters the water and i would need to evaluate a new volume each sec, when it dives in. However, i tried doing a while loop, and my code just kept running, my knowledge in MATLAB is at beginner's level, but i am keen to learn so i hope you could teach me what to do?

Code:
%INPUTS
L      = 0;   %lower limit
U      = 8.5; % upper limit
n      = 40;  % number of segments
Length = 1;
Breath = 3;
Height = 2.3;
density= 1.025;
g      = 9.81;

func = @(x) (Breath * Height);
h = (U-L)/n;

st4 = 0;
st2 = 0;

while (i < 40)

    for i = 2:h:n
        st4 = st4 + 4*func(i);
    end

    for i = 3:h:n
        st2 = st2 + 2*func(n);
    end

    Buoyancy_Force = (density*g)*(h/3*(func(1)+st4+st2+func(i)));

end
disp (Buoyancy_Force)
fprintf('step %.3f\n',i);
disp (st4)
disp (st2)

The following while loop i used i<40 , the reason why i put that was, i divided the lifeboat into 40 strips and so i was thinking my simpson's rule could evaluate at every i interval till it reached the 40th strip and stop.

Please help!

Thank you!,
Best Regards,
Noel
 

Attachments

  • lifeboat.png
    lifeboat.png
    2.2 KB · Views: 580
noelll said:
Hi,
Thank you so much for your reply,
yes the immersed volume of the lifeboat is changing as it enters the water and i would need to evaluate a new volume each sec, when it dives in. However, i tried doing a while loop, and my code just kept running, my knowledge in MATLAB is at beginner's level, but i am keen to learn so i hope you could teach me what to do?

Code:
%INPUTS
L      = 0;   %lower limit
U      = 8.5; % upper limit
n      = 40;  % number of segments
Length = 1;
Breath = 3;
Height = 2.3;
density= 1.025;
g      = 9.81;

func = @(x) (Breath * Height);
h = (U-L)/n;

st4 = 0;
st2 = 0;

while (i < 40)

    for i = 2:h:n
        st4 = st4 + 4*func(i);
    end

    for i = 3:h:n
        st2 = st2 + 2*func(n);
    end

    Buoyancy_Force = (density*g)*(h/3*(func(1)+st4+st2+func(i)));

end
disp (Buoyancy_Force)
fprintf('step %.3f\n',i);
disp (st4)
disp (st2)

The following while loop i used i<40 , the reason why i put that was, i divided the lifeboat into 40 strips and so i was thinking my simpson's rule could evaluate at every i interval till it reached the 40th strip and stop.

Please help!

Thank you!,
Best Regards,
Noel
IDK anything about MATLAB programming, but there seems to be something strange with the structure of your loops.

You calculate h = (U - L)/n, which gives you 0.2125 using the data in your script. It's not clear how MATLAB decodes i = 2:h:n or i = 3:h:n, but if your loop counter is being incremented by 0.2125 each time, that may be a problem. h is a fixed quantity; I'm just not sure what it's doing in a loop counter.
 
SteamKing said:
IDK anything about MATLAB programming, but there seems to be something strange with the structure of your loops.

You calculate h = (U - L)/n, which gives you 0.2125 using the data in your script. It's not clear how MATLAB decodes i = 2:h:n or i = 3:h:n, but if your loop counter is being incremented by 0.2125 each time, that may be a problem. h is a fixed quantity; I'm just not sure what it's doing in a loop counter.

Hi!
Thank you for your reply!
Base on my knowledge, i = 2:h:n refers to i starting value 2 will have a increment of h till it reached the value of n .

Is this causing me the problems? What would you suggest me to do instead?

Sorry to trouble you!

Noel
 
noelll said:
Hi!
Thank you for your reply!
Base on my knowledge, i = 2:h:n refers to i starting value 2 will have a increment of h till it reached the value of n .

Is this causing me the problems? What would you suggest me to do instead?

Sorry to trouble you!

Noel
Well, IDK if it's causing your problems, but trying to count from 2 to 40 in increments of 0.2125 is a little strange.

I think you need to separate the number of the section of interest (i = 1, 2, 3, ..., 40) from its location from one end of the boat (x = 0, 0.2125, 0.4250, ..., 8.5000.
Let the loop counter i count stations; you can always insert additional code into the body of the loop to calculate where a particular section is located.
 

Similar threads

Replies
31
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
10K
Replies
2
Views
6K
  • · Replies 11 ·
Replies
11
Views
3K
Replies
4
Views
21K
Replies
2
Views
2K
Replies
9
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K