## How to create a single table that shows every iteration

Asked by Scott Isler

### Scott Isler (view profile)

on 12 Sep 2019
Latest activity Commented on by Rena Berman

### Rena Berman (view profile)

on 19 Sep 2019 at 15:43
This is my code that uses the bisection method to find the maximum bending moment on a beam. Right now the output shows 16 different iterations on 16 different tables all equal to T. How can I write my code so all the tables are together in a single table? I feel like this ought to be rather simple but I can't figure it out.
f=
@(x) 33.33-5/3*x^2; %function of shear force
x1=0; %location of support A
x2=6; %location of maximum linear distributed force
eps=abs(x2-x1);
conv=.0001;
iter=0;
while eps>=conv
xc=(x2+x1)/2;
if f(xc)*f(x2)<0
x1=xc;
elseif f(xc)*f(x1)<0
x2=xc;
else
break;
end
eps=abs(x2-x1);
iter=iter+1;
T=table(iter,x1,x2,xc,f(x1),f(x2),f(xc),eps);
T.Properties.VariableNames={'iter' 'x1' 'x2' 'xc' 'fx1' 'fx2' 'fxc' 'eps'}
end

### madhan ravi (view profile)

on 13 Sep 2019
Really editing question is a smart idea??
Rena Berman

### Rena Berman (view profile)

on 19 Sep 2019 at 15:43
(Answers Dev) Restored edit

### Walter Roberson (view profile)

Answer by Walter Roberson

### Walter Roberson (view profile)

on 12 Sep 2019
Edited by Walter Roberson

### Walter Roberson (view profile)

on 13 Sep 2019

f=
@(x) 33.33-5/3*x^2; %function of shear force
x1=0; %location of support A
x2=6; %location of maximum linear distributed force
eps=abs(x2-x1);
conv=.0001;
iter=0;
while eps>=conv
xc=(x2+x1)/2;
if f(xc)*f(x2)<0
x1=xc;
elseif f(xc)*f(x1)<0
x2=xc;
else
break;
end
eps=abs(x2-x1);
iter=iter+1;
iters(iter) = iter;
x1s(iter) = x1;
x2s(iter) = x2;
xcs(iter) = xc;
fx1s(iter) = f(x1);
fx2s(iter) = f(x2);
fxcs(iter) = f(xc);
epss(iter) = eps;
end
T = table(iters(:), x1s(:), x2s(:), xcs(:), fx1s(:), fx2s(:), fxcs(:), epss(:));
T.Properties.VariableNames = {'iter' 'x1' 'x2' 'xc' 'fx1' 'fx2' 'fxc' 'eps'}