Plotting error with integral

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 Comments

Why do you need "integral" at all ?
integral f(z') dz' = -1/((nu+1)*g)*(1-g*z')^(nu+1)
STP
STP on 23 Jan 2019
Edited: STP on 23 Jan 2019
Because I have to plot equation V which should give the curve shown ; V is summation of integrals EA and EB
I gave you the antiderivative of f(z') ; this suffices to evaluate the integral of E(A) and E(B) without using MATLAB's "integral".
STP
STP on 23 Jan 2019
Edited: STP on 23 Jan 2019
Aha!
But if I plot; I do not get the curve as indicated in the picture :/
Do you get it? :/
I don't understand why you integrate Va and Vb with respect to t and not with respect to z' as given by your collection of formulae.
I put up another picture; which gives the final V function between t1 and t2 ; maybe that helps you ?
And why don't you use this formula for V and make an integration instead ?
I tried that before this : but it gave me a another error
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);
Array indices must be positive integers or logical values.
g*(1+V) instead of g(1+V)
Yup, sorry!
Even with that == Matrix dimensions must agree error
hence I resorted to the integral part; but none give me the output :/
Please include the full code with the integral-part removed.
% 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);
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.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 23 Jan 2019
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()

Categories

Find more on General Physics in Help Center and File Exchange

Tags

Asked:

STP
on 23 Jan 2019

Commented:

on 23 Jan 2019

Community Treasure Hunt

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

Start Hunting!