Help Bisection method Matlab
이전 댓글 표시
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
If your teacher wants you to find the mistake, would you learn something if someone points out to you? What is the difference if your teacher points out the mistake to you?
These are rhetorical questions.
If you want some quick answers, you should at least explain what you did (explain the math) and what you want the community to check.
Are you suggesting that the community to check the Bi-section formula? Or the mechanics of the physics problem?
ilaria scanu
2022년 6월 12일
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개)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
