Plotting error with integral
4 views (last 30 days)
Show older comments
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.


% 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 Comments
Walter Roberson
on 23 Jan 2019
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.
Answers (1)
Walter Roberson
on 23 Jan 2019
ZD is a vector. You cannot use a vector as array bounds for integral().
You have two choices:
- You can use arrayfun() to integrate from the lower bound to each of the upper bounds one at a time
- You can integrate over each of the sub-intervals, after which you can cumsum()
0 Comments
See Also
Categories
Find more on General Physics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!