How to give if...then condition ?
Show older comments
How can I give a condition statement for the following case:
for A1<=A,
e=0
for A1>A,
e=5e-03
Now, I want to use this e value (after A1>A) to calculate a new value of e at the next time instant. Say, the formula for e is,
e = v/[u/e - 2] (e on the RHS is the value of e at the previous time step and the e on LHS is the new value which I want)
How can I form a condition for the above case??
Thanks!!
1 Comment
You need to learn the difference between FOR and IF:
doc for
doc if
Once you have this difference clear in your mind, you should be able to formulate your question more clearly.
Answers (2)
Azzi Abdelmalek
on 17 Oct 2012
e=5e-03
if A1<=A,
e=0
else
e = v/[u/e - 2]
end
15 Comments
Urvi
on 18 Oct 2012
Azzi Abdelmalek
on 18 Oct 2012
show your code
Urvi
on 19 Oct 2012
Azzi Abdelmalek
on 19 Oct 2012
Edited: Azzi Abdelmalek
on 19 Oct 2012
Maybe you should reformulate your question and make it clear.
Urvi
on 19 Oct 2012
Azzi Abdelmalek
on 19 Oct 2012
try this
function dy=equation(t,y)
global b1 b2 b3 c
dy=zeros(3,1);
b1=b1+1-exp(-b3)
b2=b1-y(1)
b3=b1+b2+y(2)
if y(1)<100 & b1<0.0001 %(initially b is zero)
b1=0.01
end
dy(1)=-b1*y(1);
dy(2)=b3*y(1)+b2*y(2);
dy(3)=sqrt(b1)+y(1)+y(3);
c=[c;t b1 b2 b3]
end
Urvi
on 19 Oct 2012
Azzi Abdelmalek
on 19 Oct 2012
Edited: Azzi Abdelmalek
on 19 Oct 2012
Because the condition b1<0.0001 is always false
look at the result
find(c(:,2)<0.0001) % c(:,2) is b1,
the result is
b1 =
Empty matrix: 0-by-1
Urvi
on 19 Oct 2012
Azzi Abdelmalek
on 19 Oct 2012
Edited: Azzi Abdelmalek
on 19 Oct 2012
No, when the function is called, first you have b1=b1+1-exp(-b3), before the test. b1 is not zero
Azzi Abdelmalek
on 19 Oct 2012
Edited: Azzi Abdelmalek
on 19 Oct 2012
function dy=equation(t,y)
global b1 b2 b3 c
dy=zeros(3,1);
if y(1)<100 & b1<0.0001
b1=0.01
else
b1=b1+1-exp(-b3)
end
b2=b1-y(1)
b3=b1+b2+y(2)
dy(1)=-b1*y(1);
dy(2)=b3*y(1)+b2*y(2);
dy(3)=sqrt(b1)+y(1)+y(3);
c=[c;t b1 b2 b3]
end
Urvi
on 19 Oct 2012
Azzi Abdelmalek
on 19 Oct 2012
Edited: Azzi Abdelmalek
on 19 Oct 2012
function dy=equation(t,y)
global b1 b2 b3 c y1 yy
dy=zeros(3,1);
if y(1)>b2
b1=0.001;
end
b1=b1+1-exp(-b3);
b2=b1-y(1);
b3=b1+b2+y(2);
dy(1)=-b1*y(1);
dy(2)=b3*y(1)+b2*y(2);
dy(3)=sqrt(b1)+y(1)+y(3);
c=[c;t b1 b2 b3] ;
Urvi
on 19 Oct 2012
Sachin Ganjare
on 18 Oct 2012
if A1<=A
e= 0;
elseif A1>A
e = 5e-3;
end
e= v/(u/e_prev - 2);
e_prev = e;
Hope it helps!!!
6 Comments
Urvi
on 19 Oct 2012
Sachin Ganjare
on 19 Oct 2012
Can you describe the error?
Urvi
on 19 Oct 2012
Sachin Ganjare
on 19 Oct 2012
Can you show your code, if possible a pseudo code, to help understand the problem.
Azzi Abdelmalek
on 19 Oct 2012
Urvi, Can you post your code?
Urvi
on 19 Oct 2012
Categories
Find more on Dates and Time 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!