Undefined function or variable "t".
조회 수: 20 (최근 30일)
이전 댓글 표시
I try to run the code in the answer of: http://www.mathworks.com/matlabcentral/answers/259039-change-input-at-each-time-step-of-the-ode-solver-ode45
function yourIntegration
tResult = [];
xResult = [];
tStep = [7 14 21 28 35 42 49 56 63 70 77 84];
x0 = [64700 0 0.0033];
for index = 2:numel(tStep)
% Integrate:
beta = 0.43e-08 + (4.28e-08 - 0.43e-08) * exp(-0.20*t(index - 1))
af = @(t,x) f(t, x, beta);
t = tStep(index-1:index);
[t, x] = ode45(af, t, x0);
% Collect the results:
tResult = cat(1, tResult, t);
xResult = cat(1, xResult, x);
% Final value of x is initial value for next step:
x0 = x(end, :);
end
function dx = f(t,x, beta)
dx = [3494-0.054*x(1)-beta*x(1)*x(3); ...
beta*x(1)*x(3) - 0.41*x(2); ...
50000*x(2) - 23*x(3)];
I encountered the error of
Undefined function or variable "t". Error in yourIntegration (line 8) beta = 0.43e-08 + (4.28e-08 - 0.43e-08) * exp(-0.20*t(index - 1))
What should I do?
댓글 수: 0
답변 (1개)
Torsten
2016년 6월 14일
Must read
beta = 0.43e-08 + (4.28e-08 - 0.43e-08) * exp(-0.20*tStep(index - 1))
Best wishes
Torsten.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 General PDEs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!