Hi guys could you please help me in this if i could make loop like? I have attached m file too.
1 view (last 30 days)
Show older comments
for k=1:N
j=1
E_1=1;
while E_1>10^(-6)
j=j+1;
Calculate values;
Error=abs(calculated - assumed);
E_1=Error;
end
While
end
end
5 Comments
Stephen23
on 8 Jan 2015
Note: don't use i or j as the loop variables, as these are the names of the inbuilt imaginary unit .
Accepted Answer
Geoff Hayes
on 9 Jan 2015
Daya - look at your while loop conditions
while E_11>Err
% etc.
while E_1>Err
% etc.
end
end
The E_11 and E_1 are initialized but are never reset. So if we enter either of these two loops because the condition is satisfied, then we will never exit the loop because neither of these two variables change, so that is why you are getting stuck. The last (or next to last) line of both while loops should be the re-initializaton of the variable that is being used in the condition. Try doing that and see what happens!
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!