Implementation of formula in a single line.

2 Ansichten (letzte 30 Tage)
Raza Ali
Raza Ali am 25 Sep. 2020
Kommentiert: Raza Ali am 25 Sep. 2020
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.

Akzeptierte Antwort

madhan ravi
madhan ravi am 25 Sep. 2020
Bearbeitet: madhan ravi am 25 Sep. 2020
“Implementation of formula in a single line.”
Z = (L * A * (exp(X) - 1)) .* (X < 0) + (L * X) .* (X >= 0);
  3 Kommentare
madhan ravi
madhan ravi am 25 Sep. 2020
Corrected it.
Raza Ali
Raza Ali am 25 Sep. 2020
Thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

KSSV
KSSV am 25 Sep. 2020
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)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by