Help Bisection method Matlab
2 views (last 30 days)
Show older comments
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 Comments
Torsten
on 12 Jun 2022
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.
Answers (0)
See Also
Categories
Find more on Assembly in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!