Convert equation into code

조회 수: 1(최근 30일)
Tanush Reddy
Tanush Reddy 2022년 11월 27일
답변: Voss 2022년 11월 27일
이 질문에 Star Strider 님이 플래그를 지정함
Convert this into matlab code
c1 = 2 ; c2 = 4 ; c3 = 5
J = [10 20 30 40 50]
O = same size as J
On+1 =c1*Jn+1 + c2*Jn + c3*On
help me with this code
  댓글 수: 2
Tanush Reddy
Tanush Reddy 2022년 11월 27일
c1= 2;
c2 = 4;
c3 = 5;
J = [10:10:50]
O = [I(1) 0 0 0 0 0 0 0 0 0]
n = 1:5
i = 2:6
O(i) = c1*I(i) + c2*I(n) + c3*O(n) %Probable error in c3*O(n) part as O is not update
%Should i use for loop ??
display(O)
COndition is O(1) should be same as J(1) and im not getting accurate answers with this code.. help me rectify this code and its mistakes

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

답변(1개)

Voss
Voss 2022년 11월 27일
c1 = 2;
c2 = 4;
c3 = 5;
J = 10:10:50;
O = zeros(size(J));
O(1) = J(1);
for n = 1:numel(O)-1
O(n+1) = c1*J(n+1) + c2*J(n) + c3*O(n);
end

범주

Find more on Simscape Electrical in Help Center and File Exchange

제품

Community Treasure Hunt

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

Start Hunting!

Translated by