Why do I get error undefined function or variable?
이전 댓글 표시
% Runge Kutta
h = 0.1;
t1 = 0:h:50;
n = length(t1);
v1 = zeros(1,n);
v1(1)=0;
for i = 1:n-1
k1 = velocity1(t1(i),v1(i));
k2 = velocity1(t1(i)+h/2,v1(i)+0.5*k1*h);
k3 = velocity1(t1(i)+h/2,v1(i)+0.5*k2*h);
k4 = velocity1(t1(i)+h,v1(i)+k3*h);
v1(i+1) = v1(i) + (k1+2*k2+2*k3+k4)*h/6;
if ( abs(v1(i+1))<0 || ~isreal(v1(i+1)) )
tf = t1(i);
break
end
end
vel1_RK4 = v1(1:i);
t1_RK4 = t1(1:i);
h = 0.1;
t2 = 50:h:330;
n = length(t2);
v2 = zeros(1,n);
v2(1) = 10;
for i = 1:n-1
k1 = velocity2(t2(i),v2(i));
k2 = velocity2(t2(i)+h/2,v2(i)+0.5*k1*h);
k3 = velocity2(t2(i)+h/2,v2(i)+0.5*k2*h);
k4 = velocity2(t2(i)+h,v2(i)+k3*h);
v2(i+1) = v2(i) + (k1+2*k2+2*k3+k4)*h/6;
if ( abs(v2(i+1))<0 || ~isreal(v2(i+1)) )
tf = t2(i);
break
end
end
vel2_RK4 = v2(1:i);
t2_RK4 = t2(1:i);
figure
plot (t1_RK4,vel1_RK4,t2_RK4,vel2_RK4)
xlabel( 'Time(s)' )
ylabel( 'Velocity (m/s)' )
title( 'Velocity VS Time using Runge-Kutta' )
legend( 'V1(Before ShutDown)' , 'V2 (After ShutDown)' )
댓글 수: 2
KSSV
2020년 10월 9일
You have to define the variables velocity1 ..did you define those?
Sudhakar Shinde
2020년 10월 9일
It seems velocity1 & velocity2 variables are not defined.
답변 (1개)
Shashank Gupta
2020년 10월 12일
0 개 추천
you haven't define some variable in your code. these error occur when compiler trying to access a function or variables and it is not defined. Do check your code and see if all variable are properly declared. From the first look, "velocity" does seems like not defined. check other variable too.
카테고리
도움말 센터 및 File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!