www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/RootsOfTrigonometricPolynomialExample.m

    %% Roots Using Substitution
% You can solve polynomial equations involving trigonometric functions by
% simplifying the equation using a substitution. The resulting polynomial
% of one variable no longer contains any trigonometric functions.
%
% For example, find the values of $\theta$ that solve the equation
%
% $$ 3 \cos^2(\theta) - \sin(\theta) + 3 = 0.$$
%
% Use the fact that $\cos^2(\theta) = 1 - \sin^2(\theta)$ to express the
% equation entirely in terms of sine functions:
%
% $$-3\sin^2(\theta) - \sin(\theta) + 6 = 0.$$
%
% Use the substitution $x = \sin(\theta)$ to express the equation as a
% simple polynomial equation:
%
% $$ -3x^2 - x + 6 = 0.$$
%
% Create a vector to represent the polynomial.

% Copyright 2015 The MathWorks, Inc.

p = [-3 -1 6];

%%
% Find the roots of the polynomial.
r = roots(p)

%%
% To undo the substitution, use $\theta = \sin^{-1}(x)$. The |asin|
% function calculates the inverse sine.
theta = asin(r)

%%
% Verify that the elements in |theta| are the values of $\theta$ that solve
% the original equation (within roundoff error).
f = @(Z) 3*cos(Z).^2 - sin(Z) + 3;
f(theta)