How can I write the following Algorithm in MATLAB? What is wrong with my code?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
We have an algorithm like:
Step 1: Set ε, ρ_0,t_1. Set i=1
Step2: If a≤ε, stop.
Step 3: Calculate ∆_i. Set t_{i}^{+}=t_i+∆_i
Step 4: Calculate ρ_i.
Step 5: If b=0, go to Step 6. Otherwise, set t_{i+1}=t_{i}^{+} and go to Step 7.
Step 6: If ρ_i ≥ρ_0, set t_{i+1}=t_{i}^{+}, do something go to Step 8. Otherwise do another thing and go to Step 3 (inner cycle).
Step 7: If ρ_i ≥ρ_0 do something and go to Step 8. Otherwise do another thing and go to Step 8.
Step 8: Set i=i+1 and go to Step 2. (outer cycle)
I have written a code like this:
Set ε, ρ_0,t_1, maxiter. Calculate a, Set i=1
While (a> ε & i<maxiter)
Calculate ∆_i
Set t_{i}^{+}=t_i+∆_i
Calculate ρ_i.
Calculate b.
If b=0
If ρ_i ≥ρ_0
t_{i+1}=t_{i}^{+}
i=i+1
else
while (ρ_i <ρ_0 & b=0)
Calculate ∆_i
Set t_{i}^{+}=t_i+∆_i
Calculate ρ_i.
Calculate b.
end (out of inner cycle)
If ρ_i ≥ρ_0
t_{i+1}=t_{i}^{+}
i=i+1
do something
else
t_{i+1}=t_{i}^{+}
i=i+1
do another thing
end
end
else (beginning if)
t_{i+1}=t_{i}^{+}
If ρ_i ≥ρ_0
do something
i=i+1
else
do another thing
i=i+1
end
calculate a
end (out of outer cycle)
The code is working but it is not working as it should work, I could not find my mistake in the code. Do you have any suggestions for the code? Especially for the loop (inner cycle) between Step 3 and Step 6.
3 comentarios
Ilham Hardy
el 3 de Jul. de 2014
To be working and not to be working.. :D
Could you be more specific to describe what you see and what you got?
It is also important to put error messages (if there any) to help us help you.
Regards, IH
(PS. no pun intended)
Respuestas (0)
Ver también
Categorías
Más información sobre Logical 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!