# How to use result from first iteration from one equation and use it on other equation?

2 vues (au cours des 30 derniers jours)
Steve le 2 Déc 2020
Commenté : Steve le 3 Déc 2020
I'm trying to iterate S2 equation with e function. How to solve it?
For example for first iteration when n=0
e(n+1)=eo*sin(n) --> N=0 =--> e(1)=1*sin(0)=0
--> e(e(n+1))=e0*sin(e(n+1)-1)-->e(0)=1*sin(-1)=-0.017
s2(0)=E*(e(e(0)-ep)
-->e(-0.017)=1*sin(-1.017)=-0.017
-->s2(0)=1*(e(-0.017)-ep)
s2(0)=1*(-0.017-2)=-2.017
I wanted the program to run like that, but don't know how to do it in matlab
e0=1
n=[0:180]
e(n+1)=eo*sin(n)
S1(n+1)=E*(e(n+1)-ep)
E=1
ep=2
S2(e(n+1))=E*(e(e(n+1))-ep)
##### 2 commentairesAfficher AucuneMasquer Aucune
KSSV le 3 Déc 2020
S1(n+1)=E*(e(n+1)-ep)
What is ep in the above?
Steve le 3 Déc 2020
ep=2

Connectez-vous pour commenter.

### Réponse acceptée

KSSV le 3 Déc 2020
Check the below. Check the code, I have not checked it thoroughly. But you can follow the methid like shown. I have used anonymous function.
e0=1 ; ep = 2 ;
E=1 ;
n= 0:180 ;
e = @(n) e0*sin(n) ;
S1 = E*(e(n+1)-ep) ;
S2 = E*(e(e(n+1))-ep) ;
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Steve le 3 Déc 2020
Thanks, it works. Can yo u help me on this one too. https://www.mathworks.com/matlabcentral/answers/674418-how-to-plot-with-if-statement

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Programming Utilities dans Help Center et File Exchange

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by