I keep receiving "Error using / Arguments must be numeric, char, or logical." when I try to find value of sym function
Afficher commentaires plus anciens
I am trying to solve a system of ODE's using the Runge Kutta Method and I keep receiving the above error when I try to run it. Any help would be much appreciated!
d = @(t) sqrt(d0^2 -k*t*(d0)^2);
m = @(t) 1000*(1/6)*d^3;
Fd2 = @(t,y,v) (18*pi*v)/(1000*(d^2)) ;
F1 = @(t,y,v) v ;%dy/dt = v
F2 = @(t,y,v) Fd2/m - 9.8 % dv/dt = -g + Fd/m
h = 1;
t = 0:h:15; %Analyzing up to t = 15.
v = zeros(1,length(t));
y = zeros(1,length(t));
v(1) = 0;
y(1) = 2000;
for i = 1:1:length(t) - 1
k1 = F1(t(i),y(i),v(i))
p1 = F2(t(i),y(i),v(i))
k2 = F1(t(i)+h/2, y(i)+(h/2)*k1, v(i)+(h/2)*p1)
p2 = F2(t(i)+h/2, y(i)+(h/2)*k1, v(i)+(h/2)*p1)
k3 = F1(t(i)+h/2, y(i)+(h/2)*k2, v(i)+(h/2)*p2)
p3 = F2(t(i)+h/2, y(i)+(h/2)*k2, v(i)+(h/2)*p2)
k4 = F1(t(i)+h, y(i)+(h)*k3, v(i)+(h)*p3)
p4 = F2(t(i)+h, y(i)+(h)*k3, v(i)+(h)*p3)
y(i+1) = y(1) + h * (k1+2*k2+2*k3+k4)/6
v(i+1) = v(i) + h * (p1+2*p2+2*p3+p4)/6
end
The following is the full error I receive:
Error using /
Arguments must be numeric, char, or logical.
Error in RK>@(t,y,v)Fd2/m-9.8 (line 30)
F2 = @(t,y,v) Fd2/m - 9.8 % dv/dt = -g + Fd/m
Error in RK (line 43)
p1 = F2(t(i),y(i),v(i))
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!