How to give if...then condition ?

3 次查看(过去 30 天)
Urvi
Urvi 2012-10-17
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 个评论
Matt Fig
Matt Fig 2012-10-18
编辑:Matt Fig 2012-10-18
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.

请先登录,再进行评论。

回答(2 个)

Azzi Abdelmalek
Azzi Abdelmalek 2012-10-17
e=5e-03
if A1<=A,
e=0
else
e = v/[u/e - 2]
end
  15 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2012-10-19
编辑:Azzi Abdelmalek 2012-10-19
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] ;

请先登录,再进行评论。


Sachin Ganjare
Sachin Ganjare 2012-10-18
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 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2012-10-19
Urvi, Can you post your code?
Urvi
Urvi 2012-10-19
ya I just did..thank you.

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by