Implementation of formula in a single line.

1 回表示 (過去 30 日間)
Raza Ali
Raza Ali 2020 年 9 月 25 日
コメント済み: Raza Ali 2020 年 9 月 25 日
I want to implement the above formula in single line without using if statment.
I have tried but geting error at X=0.
X=-4:1:4;
L=2;
A=1.6732;
Z= ((max(X,0)./X).*(X.*L))+((min(0,X)./X).*(L.*(A.*exp(X)-A)))
Need to have zero at X=0.

採用された回答

madhan ravi
madhan ravi 2020 年 9 月 25 日
編集済み: madhan ravi 2020 年 9 月 25 日
“Implementation of formula in a single line.”
Z = (L * A * (exp(X) - 1)) .* (X < 0) + (L * X) .* (X >= 0);
  3 件のコメント
madhan ravi
madhan ravi 2020 年 9 月 25 日
Corrected it.
Raza Ali
Raza Ali 2020 年 9 月 25 日
Thanks

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

その他の回答 (1 件)

KSSV
KSSV 2020 年 9 月 25 日
x = linspace(-4,+4,100) ;
z = x ;
L = 2 ;
A = 1.6732;
z(x<0) = L*A*exp(x(x<0)-1) ;
plot(x,z)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by