convert from Matlab to equation (formula)
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jules Ray
el 2 de Ag. de 2021
Comentada: Jules Ray
el 3 de Ag. de 2021
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 comentarios
David Hill
el 2 de Ag. de 2021
What are Y3 and GOD initially? You define as sybolic, but treat as an array.
Respuesta aceptada
Walter Roberson
el 2 de Ag. de 2021
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.'
GOD2 = [Y3(1), Y3(2:end)-Y3(1:end-1)];
GOD2.'
So you can replace the loop with the formula I show in GOD2
Más respuestas (0)
Ver también
Categorías
Más información sobre Conversion Between Symbolic and Numeric en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!