필터 지우기
필터 지우기

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 CenterFile Exchange에서 Assembly에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by