Help Bisection method Matlab

2 次查看(过去 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