Bisection method for finding angle

1 次查看(过去 30 天)
Help with code
  3 个评论
Steven Lord
Steven Lord 2022-8-30
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.

请先登录,再进行评论。

回答(1 个)

Sam Chak
Sam Chak 2022-8-31
This should help you to visualize how to approach the problem. Since the solution space is between 0° and 90°, we can plot out the two functions over the range 0 to . and see where the intersection lies at.
x = linspace(0, pi/2, 1801);
yL = tan(x); % LHS function
yR = 1./(1 + exp(-x)); % RHS function
plot(x, yL, x, yR), grid, ylim([-0.5 1.5]), xlabel('x'), ylabel('y')
legend('LHS fcn', 'RHS fcn')
You can also transform the problem into a polynomial root-finding problem by applying Taylor series on the tangent and exponential functions:
Simplifying both sides and rearranging it yields a 7th-degree polynomial equation:
p7 = @(x) 4369/80640*x.^7 + 21/160*x.^5 + 17/48*x.^3 + 3/4*x - 1/2; % 7th-degree polynomial
fplot(p7, [0 pi/2])
grid, ylim([-0.5 0.5]), xlabel('x'), ylabel('y')
legend('p_7', 'location', 'east')
x0 = 0.6; % from 1st plot, we guess the initial point that is very close to the root
x = fzero(p7, x0) % finding the real root
x = 0.5683
This solution is merely an approximation, but a good one. Now, try applying the bisection method.

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by