convert from Matlab to equation (formula)

조회 수: 6 (최근 30일)
Jules Ray
Jules Ray 2021년 8월 2일
댓글: Jules Ray 2021년 8월 3일
Hello, I hope you are doing well
Just a simple question, I have this short code which includes a loop:
syms Y3 GOD
for j=1:numel(Y3)
if j==1
GOD(j)=Y3(j);
else
GOD(j)=Y3(j)-sum(GOD);
end
end
I am very intuitive with matlab, and I am not so good in algebra, how can I write these lines of code as formula?
I know there are several ways to convert a formula to matlab code but not the other way around....
any suggestion is higly appreciated
Best
  댓글 수: 2
David Hill
David Hill 2021년 8월 2일
What are Y3 and GOD initially? You define as sybolic, but treat as an array.
Jules Ray
Jules Ray 2021년 8월 3일
thank for your question, GOD is the output, Y3 is just a vector of 5 elements e.g. Y3=[1 2 3 4 5];
Best

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

채택된 답변

Walter Roberson
Walter Roberson 2021년 8월 2일
syms Y3 [1 5]
syms GOD [1 5]
for j=1:numel(Y3)
if j==1
GOD(j)=Y3(j);
else
GOD(j)=Y3(j)-sum(GOD(1:j-1));
end
end
GOD.'
ans = 
GOD2 = [Y3(1), Y3(2:end)-Y3(1:end-1)];
GOD2.'
ans = 
So you can replace the loop with the formula I show in GOD2

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by