Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

convert my code ; Plot using ode function

조회 수: 2 (최근 30일)
STP
STP 2019년 2월 4일
마감: MATLAB Answer Bot 2021년 8월 20일
% 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

답변 (1개)

Stephan
Stephan 2019년 2월 4일
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
STP
STP 2019년 2월 5일
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 2019년 2월 5일
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.

Community Treasure Hunt

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

Start Hunting!

Translated by