Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

convert my code ; Plot using ode function

1 vue (au cours des 30 derniers jours)
STP
STP le 4 Fév 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
% 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

Réponses (1)

Stephan
Stephan le 4 Fév 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 commentaires
STP
STP le 5 Fév 2019
yes, precisely. Thankyou!! :)
So if I just have the solutions; and I need to use the ode solver to get the plot as an output ; is there a way I can find the differential equations to put in the ode solver? As I just have the solutions and the output I wish to generate.
Stephan
Stephan le 5 Fév 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.

Cette question est clôturée.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by