이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to find the differential equation ? ode solver
조회 수: 3 (최근 30일)
이전 댓글 표시
STP
2019년 2월 5일
So I am very new to matlab ; now wish to use ode solver. I am a little stuck with a thing ; If I have an ouput plot as my objective to plot ; and I have the solutions of the differential equations - is there a way to know he differential equation which can be put in the ode solver in order to reach the objective plot ?
채택된 답변
Torsten
2019년 2월 5일
If the output plot function is f(t) and f(t0)=f0, then the corresponding ODE reads
dy/dt = f'(t) with y(t0) = f0.
This ODE should reproduce y = f.
Best wishes
Torsten.
댓글 수: 16
STP
2019년 2월 5일


% 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'})
Above mentioned is my normal code with ode solver to plot the curve shown : an the equations are the solutions of the equation I need to put in ode solver in order to get the same curve ; How to go about it in such equations ? Many thanks!
Torsten
2019년 2월 5일
dEeA = @(t,y) alfa/Tc * exp(-t/Tc);
tspan = t1;
y0 = 0;
[T1 EeA1] = ode45(dEeA,tspan,y0);
tspan = t11;
y0 = EeA1(end);
[T11 EeA2] = ode45(dEeA,tspan,y0);
plot(t1,EeA1,'-b',t11,EeA2,'--c','lineWidth',2)
STP
2019년 2월 5일
Super, thanks! Although can you tellme how did u come to dEeA; A tool or function? or you solve it manually ? ? I have a few more equations ; and I wish to be able to do it myself :)
STP
2019년 2월 5일
Super; thanks a lot!
I have this solution :
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')
And I found out the df the way you did; but when I use the ode solver; I get error -
dEeB = @(t,y) (-gamma *exp(-(t - tau1)/Tc)/Tc) ;
tspan2 = t2;
y1 = EeA1(end);
[T2 EeB1] = ode45(dEeB,tspan2,y1);
plot(t2,EeB1,'-b','lineWidth',2)
STP
2019년 2월 5일
% Constants
beta = 5;
alfa = 2.*beta./(beta+1);
Tc = 0.20;
gamma = alfa.*(2-exp(-t./Tc));
t1=0:0.01:4.4;
t2=4.4:0.01:5;
t3=5:0.01:12
dEeA = @(t,y) alfa/Tc * exp(-t./Tc);
tspan1 = t1;
y0 = 0;
[T1 EeA1] = ode15s(dEeA,tspan1,y0);
plot(t1,EeA1,'-b','lineWidth',2)
dEeB = @(t,y) -gamma *exp(-(t - tau1)/Tc)/Tc ;
tspan2 = t2;
y1 = EeA1(end);
[T2 EeB1] = ode15s(dEeB,tspan2,y1);
plot(t2,EeB1,'-b','lineWidth',2)
What I wish to replicate is this plot done via this code(without ode solver) :
% 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
Error message is ::
Error using odearguments (line 113)
Inputs must be floats, namely single or double.
Error in ode15s (line 150)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0,
options, varargin);
Torsten
2019년 2월 5일
% 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;
dEeA = @(t,y) alfa/Tc * exp(-t/Tc);
tspan = t1;
y0 = 0;
[T1 EeA1] = ode45(dEeA,tspan,y0);
tspan = t11;
y0 = EeA1(end);
[T11 EeA2] = ode45(dEeA,tspan,y0);
plot(t1,EeA1,'-b',t11,EeA2,'--c','lineWidth',2)
dEeB = @(t,y)-gamma *exp(-(t - tau1)/Tc)/Tc ;
tspan = t2;
y0 = gamma-alpha;
[T1 EeB1] = ode45(dEeB,tspan,y0);
tspan = t22;
y0 = EeB1(end);
[T11 EeB2] = ode45(dEeB,tspan,y0);
plot(t2, EeB1,'-b',t22, EeB2,'--c','lineWidth',2)
Ee2 = EeB2(end);
scatter(tau2,Ee2,'ro','lineWidth',2,'MarkerFaceColor','r')
dEeC = @(t,y) -Ee2*exp(-(t-tau2)/Tc)/Tc;
tspan = t3;
y0 = Ee2;
[T1 EeC1] = ode45(dEeC,tspan,y0);
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'})
Torsten
2019년 2월 6일
I did not conform to your misspelling of "alpha" :-)
Use
y0 = gamma-alfa;
instead of
y0 = gamma-alpha;
STP
2019년 2월 6일
편집: STP
2019년 2월 6일
Yes, I realised it aftre posting! Thanks :)
Although the third plot is off ; its not like it should be; doesnt match with the ouput plot. Does it match for you?
dEeC = @(t,y) -Ee2*exp(-(t-tau2)/Tc)/Tc;
the third equation solution is : ( gamma.*exp(-((t-tau1)./Tc)) -alfa).*exp(-((t3-tau2)./Tc));
time span be [4.4 5]
Torsten
2019년 2월 6일
But you prescribed
EeC = @(t) Ee2.*exp(-((t3-tau2)./Tc));
which does not depend on t.
And now you want to use
EeC = @(t) ( gamma.*exp(-((t-tau1)./Tc)) -alfa).*exp(-((t3-tau2)./Tc));
?
STP
2019년 2월 6일
Oh it does. Maybe this picture below will make it clear; Ee2 is nothing but the second equation we already plot with the exponential part multiplied to it.
EeA = @(t) -alfa .*exp(-t./Tc) + alfa;
EeB = @(t) gamma.*exp(-((tau2-tau1)./Tc)) -alfa;
EeC = @(t) ( gamma.*exp(-((tau2-tau1)./Tc)) -alfa).*exp(-((t3-tau2)./Tc));
t1= [0 4.4]
t2 = [4.4 5]
t3 = [5 ~]
alfa = 5
tau1 = 4.4
tau2= 5
etc


Torsten
2019년 2월 6일
According to the equations,
EeC = @(t) ( gamma.*exp(-(tau2-tau1)./Tc) -alfa).*exp(-(t-tau2)./Tc);
which means that you get
% 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;
dEeA = @(t,y) alfa/Tc * exp(-t/Tc);
tspan = t1;
y0 = 0;
[T1 EeA1] = ode45(dEeA,tspan,y0);
tspan = t11;
y0 = EeA1(end);
[T11 EeA2] = ode45(dEeA,tspan,y0);
plot(t1,EeA1,'-b',t11,EeA2,'--c','lineWidth',2)
dEeB = @(t,y)-gamma *exp(-(t - tau1)/Tc)/Tc ;
tspan = t2;
y0 = gamma-alfa;
[T1 EeB1] = ode45(dEeB,tspan,y0);
tspan = t22;
y0 = EeB1(end);
[T11 EeB2] = ode45(dEeB,tspan,y0);
plot(t2, EeB1,'-b',t22, EeB2,'--c','lineWidth',2)
Ee2 = EeB1(end);
scatter(tau2,Ee2,'ro','lineWidth',2,'MarkerFaceColor','r')
dEeC = @(t,y) -Ee2*exp(-(t-tau2)/Tc)/Tc;
tspan = t3;
y0 = Ee2;
[T1 EeC1] = ode45(dEeC,tspan,y0);
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'})
STP
2019년 2월 11일
Hi, sorry to bother again, I found out the initial conditions; and wanted to check whether they after ode solver and the above back drafting method you showed me leads to the same output; but somehow it doesnt; Can you make out whatsa wrong?
Tc = 2.0, alfa = beta=5; alfa = 2.beta/(beta+1); tau1= 2; tau2= 2.4; gamma=alfa.(2-exp(-tau1));*
Tc.*dEe/dt + Ee = -alfa.*Ek ... 1
initial condions be : for time span1= [0 t1] or eg [0 4.2] Ek = -1
for time span2 = [t1 t2] or [4.2 5] Ek = 1 How does solving eq.1 lead to below
EeA = @(t) -alfa .*exp(-t) + alfa; EeB = @(t) gamma.*exp(-(t-tau1)) - alfa;
My output comes nowhere like it should; its a straight line than the exponential curve it should be 

beta = 5;
Ek = -1;
Tc = 2.0;
tau1 = 2;
tau2 = 2.4;
gamma=alfa.*(2-exp(-tau1));
alfa = 2.*beta/(beta+1);
dEedt = @(t,y) ((-alfa.*Ek) - Ee)./Tc
t1 = [0 4.2]
y0 = 0;
[t1, EeA] = ode15s(dEedt,t1, y0);
plot(t1,EeA)
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
