Iterating in Matlab
Hello I'm fairly new to Matlab and I'm having trouble iterating. I'm trying to find the value S however the equation needed to evaluate it depends on S (second line). What is the best way to find S? Any help would be greatly appreciated (grin) My code:
For clarity, this is the problem I am trying to solve:
1. Assume a value for D.
2. Work out V from </tt>V=Q/(W*D) (values Q,W are inputted)
3. Solve S=(w*Cts*10^(I/J))/(V-Vcr)
Where:
I = 5.435-0.286*log10(w*d/v)-0.457*log10(Us/w)
J = 1.799-0.409*log10(w*d/v)-0.314*log10(Us/w)
Us = (9.81*R*S)^0.5;
if Us*d/v is between 1.2 and 70
Vcr=w*((2.5/(log10(Us*d/v)-0.06))+0.66)
Otherwise
Vcr=w*2.05
So Us and as a result I and J depend on S
4. Select another D and repeat the steps
5. Compare computed V*S values and find a minimum value
V=Q/(W*R); Us = (9.81*R*S)^0.5; if ((Us*d/v)>1.2) && ((Us*d/v)<70); Vcr=w*((2.5/(log10(Us*d/v)-0.06))+0.66); else Vcr=w*2.05; end I = 5.435-0.286*log10(w*d/v)-0.457*log10(Us/w); J = 1.799-0.409*log10(w*d/v)-0.314*log10(Us/w); S=(w*Cts*10^(I/J))/(V-Vcr);
For clarity, this is the problem I am trying to solve:
1. Assume a value for D.
2. Work out V from </tt>V=Q/(W*D) (values Q,W are inputted)
3. Solve S=(w*Cts*10^(I/J))/(V-Vcr)
Where:
I = 5.435-0.286*log10(w*d/v)-0.457*log10(Us/w)
J = 1.799-0.409*log10(w*d/v)-0.314*log10(Us/w)
Us = (9.81*R*S)^0.5;
if Us*d/v is between 1.2 and 70
Vcr=w*((2.5/(log10(Us*d/v)-0.06))+0.66)
Otherwise
Vcr=w*2.05
So Us and as a result I and J depend on S
4. Select another D and repeat the steps
5. Compare computed V*S values and find a minimum value
0
Comments
[php]
S_current = 1; %or some initial guess
S_next = some function of S_current
while abs(S_current - S_next) > convergence_threshold %tests for convergence
S_current = S_next;
S_next = some function of S_current
end
[/php]