필터 지우기
필터 지우기

code with variables changes

조회 수: 3 (최근 30일)
Lina Alhelo
Lina Alhelo 2019년 5월 30일
댓글: Walter Roberson 2019년 5월 30일
Hi all
I have to write code for the following
Y_k = Ax_k + b
Z_k= Y_k +C
Now for K from 0 -200 the A = 2 and b=3,C =2
for K from 201- 400 the A = 4 and b=5, C=2
what code I can write to Specify these conditions? I mean chang in K, change the parameters values.

채택된 답변

Walter Roberson
Walter Roberson 2019년 5월 30일
If you have the Symbolic Toolbox, the easiest way can be to use piecewise()
Otherwise:
A = @(k) (k >= 0 & k<=200) .* 2*ones(size(k)) + (k>200 & k<=400) .* 4*ones(size(k));
b = @(k) (k >= 0 & k<=200) .* 3*ones(size(k)) + (k>200 & k<=400) .* 5*ones(size(k));
C = @(k) (k >= 0 & k<=400) .* 2*ones(size(k));
Y = @(k) A(k) + b(k);
Z = @(k) Y(k) + C(k);
fplot(Z, [-20 420])
  댓글 수: 4
Lina Alhelo
Lina Alhelo 2019년 5월 30일
Thanks once again.
No, actaully it is Y= A*X_k+b
k is a subscript x1, x2 , x3 and so on. X is values only . we can start from x1
Walter Roberson
Walter Roberson 2019년 5월 30일
Then the code I gave should work.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by