How to create a single table that shows every iteration

4 visualizaciones (últimos 30 días)
Scott Isler
Scott Isler el 12 de Sept. de 2019
Comentada: Rena Berman el 19 de Sept. de 2019
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
  2 comentarios
madhan ravi
madhan ravi el 13 de Sept. de 2019
Really editing question is a smart idea??
Rena Berman
Rena Berman el 19 de Sept. de 2019
(Answers Dev) Restored edit

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 12 de Sept. de 2019
Editada: Walter Roberson el 13 de Sept. de 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'}

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by