How to create a single table that shows every iteration

5 ビュー (過去 30 日間)
Scott Isler
Scott Isler 2019 年 9 月 12 日
コメント済み: Rena Berman 2019 年 9 月 19 日
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 件のコメント
madhan ravi
madhan ravi 2019 年 9 月 13 日
Really editing question is a smart idea??
Rena Berman
Rena Berman 2019 年 9 月 19 日
(Answers Dev) Restored edit

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 9 月 12 日
編集済み: Walter Roberson 2019 年 9 月 13 日
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'}

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by