Plotting error: I am trying to plot the equations and the output should be as shown but its not

3 Ansichten (letzte 30 Tage)
beta=5;
t1=0:0.1:4.4;
alfa=2.*beta/(beta+1);
E1=-alfa .*exp(-tau1.*t1) + alfa
plot(t1,E1);
gamma=alfa.*(2-exp(-tau1));
tau1=2
tau2=2.4;
t2=4.4:0.01:5;
E2=(gamma.*exp(-(0.4).*t2))-(5/3);
plot(t2,E2);
What am I doing wrong? The fist equation I can plot as it is, but not the second E2. which is the part between t1 and t2 on the plot.

Akzeptierte Antwort

Stephan
Stephan am 2 Jan. 2019
Bearbeitet: Stephan am 3 Jan. 2019
Hi,
try:
% Constants
beta=5;
alfa = 2.*beta/(beta+1);
tau1=2;
tau2=2.4;
gamma=alfa.*(2-exp(-tau1));
% Time frames
t1=0:0.01:tau1;
t11 = tau1:0.01:4.4;
t2 = tau1:0.01:tau2;
t22 = tau2:0.01:4.4;
t3 = tau2:0.01:4.4;
% Part A
EeA = @(t) -alfa .*exp(-t) + alfa;
EeA1 = EeA(t1);
EeA2 = EeA(t11);
plot(t1,EeA1,'-b',t11,EeA2,'--g','lineWidth',2)
hold on
Ee1 = EeA(tau1);
scatter(tau1,Ee1,'ro','lineWidth',2,'MarkerFaceColor','r')
% Part B
EeB = @(t) gamma.*exp(-(t-tau1)) - alfa;
EeB1 = EeB(t2);
EeB2 = EeB(t22);
plot(t2, EeB1,'-b',t22, EeB2,'--g','lineWidth',2)
Ee2 = EeB(tau2);
scatter(tau2,Ee2,'ro','lineWidth',2,'MarkerFaceColor','r')
% Part C
EeC = @(t) Ee2.*exp(-(t3-tau2));
EeC1 = EeC(t3);
plot(t3, EeC1,'-b','lineWidth',2)
hold off
results in:
plot_new.PNG
This version should be correct.
Best regards
Stephan
  5 Kommentare
Stephan
Stephan am 23 Jan. 2019
Bearbeitet: Stephan am 23 Jan. 2019
ZD is not a scalar - it is a row vevtor:
This is why you get the error. Look also at the content of ZD - it is all Inf

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

madhan ravi
madhan ravi am 2 Jan. 2019
Define them as piecewise curves and then plot them.

Kategorien

Mehr zu Physics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by