Plotting error with integral

10 次查看(过去 30 天)
STP
STP 2019-1-23
The photo represents the equations I wish to put in matlab which when plot gives a curve shown as well. I am putting my code, with all the variables and the values; but seems with the integral I have some error. any help would be appreciated.
V1.JPG
% Constants
beta=5;
alfa = 2.*beta/(beta+1);
tau1=4.4;
tau2=5;
Tc=1.24;
Ta=0.66;
g=0;
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;
T=t1./Ta;
Z=1;
F=(1-g.*Z);
V=(Ta./Tc).*([log(1-g)].^-1);
Va=@(t) (-alfa .*exp(-t./Tc)).*F.^V+ (alfa-1);
Va1=Va(t1);
plot(t1,Va1);
hold on;
T2=t2./Tc;
Vb=@(t) (gamma.*exp(-((t-tau1)./Tc))).*F.^V -(alfa-1);
Vb1=Vb(t2);
plot(t2,Vb1);
TD=t1;
ZD=(1./g).*[1-((1-g).^(T-TD))];
Voltage = integral(Vb,0,ZD, 'ArrayValued',true) + integral(Va, ZD,1, 'ArrayValued',true);
Error using integral (line 85)
A and B must be floating-point scalars.
  13 个评论
STP
STP 2019-1-23
% 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;
T=t1./Ta;
Z=1;
F=(1-g.*Z);
V=(Ta./Tc).*([log(1-g)].^-1);
Va=@(t) (-alfa .*exp(-t./Tc)).*F.^V+ (alfa-1);
Va1=Va(t1);
hold on;
T2=t2./Tc;
Vb=@(t) (gamma.*exp(-((t-tau1)./Tc))).*F.^V -(alfa-1);
Vb1=Vb(t2);
TD=t1;
ZD=(1./g).*[1-((1-g).^(T-TD))];
F1 = [1-(1-g.*ZD).^(1+V)].*([g.*(1+V)]^-1);
F2 = [(1-g.*ZD).^(1+V) -(1-g).^(1+V)].*([g.*(1+V)]^-1);
Voltage = @(t) ((gamma.*exp(-(t-tau1)./Tc)).*F1 -(alfa-1).*ZD - alfa .*exp(-t./Tc).*F2 + (alfa-1).*(1-ZD));
Voltage2=Voltage(t2);
plot(t2,Voltage2, '-b','lineWidth',2);
Walter Roberson
Walter Roberson 2019-1-23
t2 is 1 x 61 and it is passed as t into Voltage, so (gamma.*exp(-(t-tau1)./Tc)) is 1 x 61.
F1 is 1 x 441.
You cannot .* between a 1 x 61 and a 1 x 441.
The next part of the expression -(alfa-1).*ZD is 1 x 441.
t2 is 1 x 61 and it is passed as t into Voltage, so alfa .*exp(-t./Tc) is 1 x 61.
F2 is 1 x 442.
You cannot .* between a 1 x 61 and a 1 x 442.
The next part of the expression (alfa-1).*(1-ZD) is 1 x 441.
F2 is calculated as
F2 = [(1-g.*ZD).^(1+V) -(1-g).^(1+V)].*([g.*(1+V)]^-1);
Notice that here the space between the ) and the -( acts to separate array elements, so the 1 x 441 on the left side is then appended with the 1 x 1 on the right to generate 1 x 442 total.
g is 0 so 1-g is 1, and log(1) is 0. 0^-1 is infinity. Therefore in
V=(Ta./Tc).*([log(1-g)].^-1);
V will become infinity.
In F1 and F2 you raise values to V, which is going to drive the values to either 0 or infinity. But you have g.* times those and g is 0, so you have 0 * infinity. Your F1 and F2 therefore become completely nan.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2019-1-23
ZD is a vector. You cannot use a vector as array bounds for integral().
You have two choices:
  1. You can use arrayfun() to integrate from the lower bound to each of the upper bounds one at a time
  2. You can integrate over each of the sub-intervals, after which you can cumsum()

类别

Help CenterFile Exchange 中查找有关 General Physics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by