I would like to elvaluate the speed of a float as it travels through the water column with depth/time dependent seawater density. The vector rho is the density profile of the sea water from 1000m to 0m. I would like o pass it through the function to evaluate speed.
clear;
close ;
%% m files for obtaining sea water denstiy profile
Sea_Water_Density_s_t_p;
Float_Velocity_Calculation;
tspan=[0 1 1000];
y0 =[1000,0,1030];
rho=descending_rho_profile;
[t,y]=ode45(@(t,y) f(t,y,rho),tspan,y0);
hold off
plot(t,y(:,2))
grid on
Here is my function:
function speed=f(t,v,rho)
Cd=.16;
A=.0613;
m=82.25;
V=0.0809815;
%rho=1030;
g=9.81;
speed=[v(2); (rho*V*g/(m+V*rho))-(m*g/(m+V*rho))-((1/(2*m+V*rho)*Cd*A.*rho.*v(2).^2))];
end

 Akzeptierte Antwort

Alan Stevens
Alan Stevens am 31 Jul. 2020

0 Stimmen

I assume this represents some object sinking through changing desity sea water. The following shows how you might do it, though you will need to replace my simple linear density change with whatever you think is appropriate.
tspan=0:1000;
y0 =[0 0];
[t,y]=ode45(@f,tspan,y0);
subplot(2,1,1)
plot(t,y(:,1))
grid on
xlabel('time'),ylabel('depth')
subplot(2,1,2)
plot(t,y(:,2))
grid
xlabel('time'),ylabel('speed')
function speed=f(~,y)
Cd=.16;
A=.0613;
m=82.25;
V=0.0809815;
depth = y(1);
rho = interp1([0 10000],[1030 1070], depth); %This is just a linear interpolation between two values
% Needs to be replaced with
% your own relationship.
g=9.81;
speed=[y(2); (rho*V*g/(m+V*rho))-(m*g/(m+V*rho))-((1/(2*m+V*rho)*Cd*A.*rho.*y(2).^2))];
end

6 Kommentare

Jestoni Orcejola
Jestoni Orcejola am 2 Aug. 2020
How to use a nonlinear interpolation? I have a vector rho I want to pass through the equation.
Alan Stevens
Alan Stevens am 2 Aug. 2020
Just replace my interp1 with spline(D,R,depth), where R is vector of known rho values at positions D, and depth is the value at which you want rho.
Jestoni Orcejola
Jestoni Orcejola am 15 Aug. 2020
I have a 1001x1 matrix that contains the volume change, but it only changes for certain amount of time until it stays constant. For example volume changes for 60 s then stays constan after that, how do I pass that through the equation? I'm assuming I can use a spline here. Unless my assumption here is wrong.
Alan Stevens
Alan Stevens am 15 Aug. 2020
Yes, a spline should work.
Jestoni Orcejola
Jestoni Orcejola am 9 Sep. 2020
What if I want to count down whith the interpolation. Is that possible?
Alan Stevens
Alan Stevens am 10 Sep. 2020
Interpolation is just that - it doesn't matter about direction! The interpolation routine will just take the depths you specify and spit out the corresponding densities.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interpolation finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by