3rd-order Runge-Kutta and 3rd order Adams-bashforth
조회 수: 5 (최근 30일)
이전 댓글 표시
Ordinary Differential Equation Water tank flow rate problem:
I attached a picture of the problem I need to solve using 3rd-order Runge-Kutta for the first h2 and h3 and points 3 to 1501 using the 3rd order Adams-Bashforth method.
I'm having trouble running the code for both to solve the given dh/dt equation (in the picture).
Here is what I have so far:
%Start. clear
%Define the size of the step:
h=0.5; x=0:h:2; t=0:150;
%Define variables:
V1=0.001; %Velocity 1, m^3/s.
V2=0.0008; %Velocity 2, m^3/s.
p=999.97; %Density, kg/m^3.
C=pi/5; %s^-1.
Apipe=0.002; %Area of pipe (tank outlet pipe), m^2.
Atank=0.2; %Area of tank, m^2.
g=9.81; %Gravity, m/s.
x=0.5; %Height of fluid in tank, m.
y(i)=0; %Initial
a2=0.5; a3=1; b21=0.5; b31=-1; b32=2; c1=1/6; c2=4/6; c3=1/6; y=zeros(size(x));
%Runge-Kutta to estimate h2 and h3:
for i=1:3
%Evaluate slope at xi,yi.
K1=(V1*p+V2*p*cos(C*t(i))-p*Apipe*sqrt(2*g*h))/(p*Atank);
%Evaluate slope at the first intermediate point.
xp=x(i)+a2*h;
yp=y(i)+b21*K1*h;
K2=
%Evaluate slope at the second intermediate point.
xp=x(i)+a3*h;
yp=y(i)+b31*K1*h+b32*K2*h;
K3=yp+;
slope=c1*K1+c2*K2+c3*K3;
%Calculate the next y.
y(i+1)=y(i)+h*slope;
end
%Plot height of water (h) vs. time, for 0=<t=<150.
figure
plot(x,y)
%3rd Order Adams-Bashforth for remaining points (i=3 to 1501):
y(i) = (V1*p+V2*p*cos(C*t)-p*Apipe*sqrt(2*g*h))/(p*Atank); %dh/dt.
for i = 3:1501
y(i+1) = y(i)+h/12*(23*f(i)-16*f(i-1)+5*f(i-2));
end
%Plot height of water (h) vs. time, for 0=<t=<150.
figure
plot(x,y)
I really appreciate any help! Let me know if something is missing or hard to read.
댓글 수: 0
답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!