Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
convert my code ; Plot using ode function
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
% Constants
beta=5;
alfa = 2.*beta/(beta+1);
tau1=4.4;
tau2=5;
Tc=0.20;
gamma=alfa.*(2-exp(-tau1));
% Time frames
t1=0:0.01:tau1;
t11 = tau1:0.01:8;
t2 = tau1:0.01:tau2;
t22 = tau2:0.01:8;
t3 = tau2:0.01:8;
% Part A
EeA = @(t) -alfa .*exp(-t./Tc) + alfa;
EeA1 = EeA(t1);
EeA2 = EeA(t11);
plot(t1,EeA1,'-b',t11,EeA2,'--c','lineWidth',2)
Now, I wish to do it with a ode function; I tried the below but unsuccessful ; I get error- Error in solve_E (line 13)
function dEdt = simple_ode(t,E)
dEdt = @(t) -alfa .*exp(-t./Tc) + alfa;
end
function solve_E
initial_E = 0;
time_range = [0, 4.4];
%% Constants
beta=5;
alfa = 2.*beta/(beta+1);
tau1=4.4;
tau2=5;
Tc=0.20;
gamma=alfa.*(2-exp(-tau1));
[t_values, E_values]= ode15s(@(t,E) simple_ode(t,E),time_range,initial_E);
plot(t_values,E_values);
end
0 comentarios
Respuestas (1)
Stephan
el 4 de Feb. de 2019
Hi,
try:
solve_E
function solve_E
initial_E = 0;
time_range = [0, 4.4];
% Constants
beta=5;
alfa = 2.*beta/(beta+1);
tau1=4.4;
tau2=5;
Tc=0.20;
gamma=alfa.*(2-exp(-tau1));
[t_values, E_values]= ode15s(@simple_ode,time_range,initial_E);
plot(t_values,E_values);
function dEdt = simple_ode(t,~)
dEdt = -alfa .*exp(-t./Tc) + alfa;
end
end
gamma and tau2 are not needed in this code, they are unused.
Best regards
Stephan
6 comentarios
Stephan
el 5 de Feb. de 2019
Calculate the analytic derivates of your functions. If you have access to Symbolic Toolbox, you can use this to calculate the derivatives and then you can create a function that is suitable for ode solvers.
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!