I need to set up a Runge Kutta solver for water leaving a bucket through a certain diameter nozzle as function of time, it says array indices must be positive integers/log val

1 Ansicht (letzte 30 Tage)
rnoz=1.049/2
rtank=120/2
Dnoz=1.049
Dtank=120
g=386.088
t=10
h=60
y=(0:200)
N:50
y(1)=240
F_y =-(((rnoz^2)/(rtank^2))*sqrt((2*g)/(1-(Dnoz/Dtank)^4)))*sqrt(y(1))*h+y(1)
for i=0:60:200
k_1 = F_y(y(i))
k_2 = F_y(y(i)+0.5*h*k_1)
k_3 = F_y(y(i)+0.5*h*k_2)
k_4 = F_y(y(i)+k_3*h)
y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h
end

Antworten (1)

Alan Stevens
Alan Stevens am 12 Nov. 2021
Indices in Matlab start at 1, not 0, so you need
for i=1:60:200
not
for i=0:60:200
  3 Kommentare
Alan Stevens
Alan Stevens am 13 Nov. 2021
Bearbeitet: Alan Stevens am 13 Nov. 2021
You probably want to define your function F_y as
F_y = @(y) -(((rnoz^2)/(rtank^2))*sqrt((2*g)/(1-(Dnoz/Dtank)^4)))*sqrt(y)*h+y;
Also note that if you increment i by 60 each iteration, then your k values still won't make sense (they will be calculated incorrectly). Just let
i = 1: ceil(200/h);
or something like that. (I suspect h = 60 is far too large a step size!).

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by