How to create a single table that shows every iteration

5 Ansichten (letzte 30 Tage)
Scott Isler
Scott Isler am 12 Sep. 2019
Kommentiert: Rena Berman am 19 Sep. 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 Kommentare
madhan ravi
madhan ravi am 13 Sep. 2019
Really editing question is a smart idea??
Rena Berman
Rena Berman am 19 Sep. 2019
(Answers Dev) Restored edit

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 12 Sep. 2019
Bearbeitet: Walter Roberson am 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'}

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by