how to write a matlab prog. for the exp. z(t)=y^3 where y=x when 0<=t<=1 ; y=3*x when 1<t<=2.

6 ビュー (過去 30 日間)
expression : z(t)=y^3
where y=x when 0<=t<=1
y=3*x when 1<t<=2
how to write a matlab program for this expression?
i guess if condition can be used, but exactly how to write ?
  3 件のコメント
ravishankar
ravishankar 2013 年 4 月 15 日
z is a function of t and y is a function of x. Actually I want to have an idea of using if condition which i am not clear at present.
Yao Li
Yao Li 2013 年 4 月 15 日
Is x another input argument?

サインインしてコメントする。

採用された回答

Yao Li
Yao Li 2013 年 4 月 15 日
if (t>=0&&t<=1)
y=x;
elseif (t>1&&t<=2)
y=3*x;
else
end
  2 件のコメント
ravishankar
ravishankar 2013 年 4 月 15 日
thank u.... same thing i even tried ,but i am getting a warning as ??? *Operands to the and && operators must be convertible to logical scalar values.
Error in ==> Untitled5 at 2 if (t>=0&&t<=1)*
Yao Li
Yao Li 2013 年 4 月 15 日
編集済み: Yao Li 2013 年 4 月 15 日
I am sure this expression is correct. Make sure t is a number not a matrix or an array.If t is a matrix or array, add a for loop and check if condition for each element of the matrix or array.

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2013 年 4 月 15 日
編集済み: Andrei Bobrov 2013 年 4 月 15 日
k = [0 1 3 0];
[j1,j1] = histc(t,[-inf,0,(1:2)-eps(100),inf]);
z = (k(j1)*x).^3;

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by