Convert equation into code

2 次查看(过去 30 天)
Tanush Reddy
Tanush Reddy 2022-11-27
回答: Voss 2022-11-27
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 个评论
Steven Lord
Steven Lord 2022-11-27
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
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

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by