MATLAB Answers

How to compute equation only for x(y>0)

1 view (last 30 days)
LB
LB on 21 Sep 2019
Commented: LB on 21 Sep 2019
Hello,
I have time, t on the x axis and power, Pw on the y axis. I want to compute the following equations for only times, t where Pw is positive. How can I do that?
% calculating alphar dependent on t
for tidx = 2:length(t)-1
alphar = Cr(tidx).*Mv*g
end
% calculating three summation terms
x = 0;
for tidx = 2:length(t)-1
x = x+(V(tidx)).^3;
end
y=0;
for tidx = 2:length(t)-1
y = y+V(tidx);
end
z=0;
for tidx=2:length(t)-1
z = z+(V(tidx)*(V(tidx+1)-V(tidx-1)));
end
% Want to calculate below equation only for t at Pw>0 (Pw calculation shows below)
Ew = (1369*((alphaa*x)+(alphar.*y)+(alphai*z)))/1000 % alphaa and alphai are constants. alphar is only one dependent on t (shown first line above)
Pw calculation shows below
for tidx=2:length(t)-1
a = (V(tidx+1)-V(tidx-1))/(2*(t(tidx+1)-t(tidx-1)));
A = ((1/2)*Rhoa*Cd*Af*(V(tidx).^3));
G = (Cr(tidx).*Mv*g*cos(0).*V(tidx));
I = (1.1*Mv.*a.*V(tidx));
Pw(tidx-1) = (A+G+I)/1000;
end

  2 Comments

darova
darova on 21 Sep 2019
What to do with those t (Pw<=0)?
LB
LB on 21 Sep 2019
Want to ignore t(pw<0). just want to use t(pw>=0)

Sign in to comment.

Answers (1)

darova
darova on 21 Sep 2019
Take Ew where Pw>0
Ew = (1369*((alphaa*x)+(alphar.*y)+(alphai*z)))/1000 % alphaa and alphai are constants. alphar is only one dependent on t (shown first line above)
Ew1 = Ew(Pw>0);

  7 Comments

Show 4 older comments
LB
LB on 21 Sep 2019
Hi Darova,
What you are saying makes sense and works. However, for x, y and z, i was calculating the way I have them because they are summation terms.
x is summation from n=1 to n=t of Vn^3
y is summation from n=1 to n=t of Vn
z is summation from n=1 to n=t of Vn(t+1)-Vn(t-1)
If I change x to the way you have it above, that isn't performing the summation?
darova
darova on 21 Sep 2019
That isn't performing the summation
% Want to calculate below equation only for t at Pw>0 (Pw calculation shows below)
The question: do x,y and z depend on t? What is value of x at specific t?
LB
LB on 21 Sep 2019
Yes, x, y and z all depend on t given in the summation equation above....

Sign in to comment.

Tags

Products