
Solve equation by fzeros
    3 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I'm solving the equation  by using fzero.
 by using fzero.
 by using fzero.
 by using fzero.My code is:
fzero(@(x) x-4*sin(x), -10)
Result just has ONE root. How to show ALL roots of equation by using fzero ?!
0 件のコメント
回答 (2 件)
  Sam Chak
      
      
 2022 年 4 月 14 日
        
      編集済み: Sam Chak
      
      
 2022 年 4 月 14 日
  
      The fzero requires initial guess. Pick the initial value that is closest to the root:
fzero(@(x) x - 4*sin(x), pi)
and it will return another solution.
Can also try this Taylor series expansion method to "guess" the initial values:
syms x
fun = x - 4*sin(x);
T9 = taylor(fun, x, 'Order', 9)
fplot([fun T9])
grid on
xlabel('x')
ylabel('f(x)')
legend('x - 4*sin(x)', 'Taylor9', 'location', 'northwest')
p = sym2poly(T9);
g = roots(p);
g(imag(g) ~= 0) = []    % initial guesses of the approximated roots
r1 = fzero(@(x) x - 4*sin(x), g(1))
r2 = fzero(@(x) x - 4*sin(x), g(2))
r3 = fzero(@(x) x - 4*sin(x), g(3))
T9 = x^7/1260 - x^5/30 + (2*x^3)/3 - 3*x
g =
         0
   -2.4661
    2.4661
r1 =      0
r2 =   -2.4746
r3 =    2.4746

0 件のコメント
  Star Strider
      
      
 2022 年 4 月 14 日
        It is straightforward to find all the roots.  
One approach — 
N = 6;
x = linspace(-N, N);
y = x-4*sin(x);
zxi = find(diff(sign(y)));                                  % Approximate Zero-Crossing Indices
for k = 1:numel(zxi)
    x0(k) = fzero(@(x) x-4*sin(x), x(zxi(k)));              % Calculate Exact Zero-Crossings
end
figure
plot(x, y)
hold on
plot(x0, zeros(size(x0)), 'rs')
hold off
grid
legend('$y(x) = x-4sin(x)$','$Roots$', 'Location','best', 'Interpreter','latex')
.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



