Is there a way to do this in a more compact way?

1 view (last 30 days)
Hello,i have to convert this code as a while loop and also it should be more compact than this form.It includes some hints for convert. Thanks
% is there a way to do this in a more compact way?
a=50;
b=-50;
for k=0:100 % use while loop
fa=1-a+sin(a); %*
fb=1-b+sin(b); %*
if(fa*fb<0)
al=a;
c=(a+b)/2;
br=b;
fal=1-al+sin(al); %*
fc=1-c+sin(c); %*
fbr=1-br+sin(br); %*
if(fal*fc<0)
a=al;
b=c;
end
if(fc*fbr<0)
a=c;
b=br;
end
if abs(b-a)<10^-4 % integrate this into while loop
disp([k (b+a)/2])
end
end
end

Answers (0)

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!