Implementation of formula in a single line.

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일

0 개 추천

“Implementation of formula in a single line.”
Z = (L * A * (exp(X) - 1)) .* (X < 0) + (L * X) .* (X >= 0);

댓글 수: 3

Raza Ali
Raza Ali 2020년 9월 25일
Thank you, after inserting L its woring.
madhan ravi
madhan ravi 2020년 9월 25일
Corrected it.
Raza Ali
Raza Ali 2020년 9월 25일
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
KSSV 2020년 9월 25일

0 개 추천

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)

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

질문:

2020년 9월 25일

댓글:

2020년 9월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by