ODE function - plot not as desired
조회 수: 4 (최근 30일)
이전 댓글 표시

The above equations give me the plot shown And I am attaching the code for the same;
% Constants
beta=5;
alfa = 2.*beta/(beta+1);
tau1=4.4;
tau2=5;
Tc=1.24;
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)
hold on
Ee1 = EeA(tau1);
scatter(tau1,Ee1,'ro','lineWidth',2,'MarkerFaceColor','r')
% Part B
EeB = @(t) gamma.*exp(-((t-tau1)./Tc)) -alfa;
EeB1 = EeB(t2);
EeB2 = EeB(t22);
plot(t2, EeB1,'-b',t22, EeB2,'--c','lineWidth',2)
Ee2 = EeB(tau2);
scatter(tau2,Ee2,'ro','lineWidth',2,'MarkerFaceColor','r')
% Part C
EeC = @(t) Ee2.*exp(-((t3-tau2)./Tc));
EeC1 = EeC(t3);
plot(t3, EeC1,'-b','lineWidth',2)
hold off
xlabel('t');
ylabel('E_e');
xticklabels({'0', '4.4', '5'})
xticks([ 0 4.4 5])
xticklabels({'0', '4.4', '5'})
xticklabels({'0', 't1', 't2'})
Now if I wish to use 'ode function' ; how to achieve the same output i.e. plot ? Do I need to use 'anti derivative' of these equations ? Objective is to get the same plot; maybe im understanding ode wrong - and the answer is simple . Any examples or reference would be appreicated :) thanks :)
채택된 답변
Cris LaPierre
2019년 2월 5일
How are you trying to use odefunction? Or why?
it is for converting symbolic expressions to function handles for ODE solvers. To be used in an ODE solver, your equations need to be differential equations. Yours are not.
댓글 수: 2
Cris LaPierre
2019년 2월 6일
I assume you have your reasons for going backwards...
Yes, you need to differentiate the equations you have, solve them with an ode solver, and then replot. I'm not worrying about recreating the plot exactly. I've got to leave something for you to do.
% Constants
beta=5;
alfa = 2.*beta/(beta+1);
tau1=4.4;
tau2=5;
Tc=1.24;
gamma=alfa.*(2-exp(-tau1));
Ee1 = -alfa.*exp(-tau1./Tc) +alfa;
Ee2 = gamma.*exp(-(tau2-tau1)./Tc) -alfa;
% Create difference equations
syms EeA(t) EeB(t) EeC(t)
eqA = diff(EeA(t),t) == diff(-alfa .*exp(-t./Tc) + alfa)
eqB = diff(EeB(t),t) == diff(gamma.*exp(-((t-tau1)./Tc)) -alfa)
eqC = diff(EeC(t),t) == diff(Ee2.*exp(-((t-tau2)./Tc)))
% Convert to fxn handles
odefunA = odeFunction(rhs(eqA),EeA(t))
odefunB = odeFunction(rhs(eqB),EeB(t))
odefunC = odeFunction(rhs(eqC),EeC(t))
% Solve ODE
[tA,yA] = ode45(odefunA,[0 tau1],0);
[tB,yB] = ode45(odefunB,[tau1 tau2],Ee1);
[tC,yC] = ode45(odefunC,[tau2 8],Ee2);
figure
plot(tA,yA,tB,yB,tC,yC)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Equation Solving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!