Help Bisection method Matlab

1 回表示 (過去 30 日間)
ilaria scanu
ilaria scanu 2022 年 6 月 12 日
コメント済み: Torsten 2022 年 6 月 12 日
Hi! I have to write a code using the bisection method. The teacher said to double check it because there is a mistake, but it looks fine to me. Could you please help me to find out what's wrong? The exercise is attached
Here is my code
a = 0.22; b = 0.08; % dimensions of the spring system [m]
K1 = 1600; % first spring system coefficient [N/m]
K2 = 1e5; % second spring system coefficient [N/m3]
L0 = sqrt(a^2+b^2); % initial spring length [m]
L = @(x) sqrt(a^2+(b+x).^2); % deformed spring length [m]
u = @(x) L(x)-L0; % deformed distance [m]
Fs = @(x) K1.*u(x)+K2.*u(x).^3; % applied force to deform spring [N]
W = @(x) 2.*Fs(x).*(b+x)./L(x); % weight force to deform the system of springs [N]
x0 = 0; xn = 0.25; % x interval
X = linspace(x0,xn);
plot(X,W(X)) % mass W in the interval X
hold on
Q = 400; % applied force to the system [N]
n = 100; % number of iterations to define root
for i = 1:n % Bisection method for an applied force Q in an interval X
xm = (x0+xn)/2; % estimated solution, midpoint of the interval
if (W(x0)-Q)*(W(xm)-Q) < 0 % check of which subinterval contains the solution
xn = xm;
else
x0 = xm;
end
plot(xm,W(xm),'*r') % plot of each estimated solution
end
  3 件のコメント
ilaria scanu
ilaria scanu 2022 年 6 月 12 日
I was asking mainly about the bisection, I think the mechanics of the physics should be correct
Torsten
Torsten 2022 年 6 月 12 日
Except for that you should leave the bisection loop earlier than after 100 iterations (based on abs(W(xm)-Q) and abs(x0-xm)), I can't see anything wrong in your code.

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

回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by