Undefined function or variable "t".
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Torsten
am 14 Jun. 2016
Must read
beta = 0.43e-08 + (4.28e-08 - 0.43e-08) * exp(-0.20*tStep(index - 1))
Best wishes
Torsten.
0 Kommentare
Siehe auch
Kategorien
Mehr zu General PDEs finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!