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.

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 ?

 采纳的回答

if (t>=0&&t<=1)
y=x;
elseif (t>1&&t<=2)
y=3*x;
else
end

2 个评论

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)*
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 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息

产品

标签

Community Treasure Hunt

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

Start Hunting!

Translated by