Exercise 8

1. Enter a unary function in MATLAB and save it, for example

f(x)=x^3+(x-0.98)^2/(x+1.25)^3-5*(x+1/x).

Create a new edit window and enter
function y=damax(x);
y=x^3+(x-0.98)^2/(x+1.25)^3-5*(x+1/x);
Then click Save, set the path to the default directory, name the file damax.m, and save.

2. Use two methods to find the roots of the above functions.

(1)>> a=fzero('damax',[-100,100])

a =

    2.4164
(2)>> y=inline('x^3+(x-0.98)^2/(x+1.25)^3-5*(x+1/x)');
>> a=fzero(y,[-100,100])

a =

    2.4164

3. Find the extreme value of the above function.

minimum
>> a=fminbnd('damax',-100,100)

a =

  -99.9999
maximum
>> -y=inline('-x^3-(x-0.98)^2/(x+1.25)^3+5*(x+1/x)');
>> a=fminbnd(-y,-100,100)

a =

   99.9999

4. What will happen if the function is not saved in the default directory?

If it is not saved in the default directory, the system will prompt:
>> a=fminbnd('damax',-100,100)
Undefined function or variable 'damax'.

Error fminbnd (line 228)
x= xf; fx = funfcn(x,varargin{:});

5. Construct a polynomial, find the roots, and then find the original polynomial from the roots. Is the resulting polynomial the same as the original polynomial and why?

      The resulting polynomial is not necessarily the same as the original polynomial. Because the root finding method used here is to first convert the polynomial into an adjoint matrix, and then find the eigenvalues, there will be approximations when taking the roots, so when the original polynomial is obtained from the roots, there will also be approximations, so the obtained The polynomial may differ from the original polynomial.

6. What method does MATLAB use to find the roots of a polynomial, and what are the advantages compared with traditional methods? 

MATLAB finds the roots of a polynomial with an M-file and a method for finding zero values, using an fzero function.

Advantages: It appears to be more mathematical, and can easily find the roots of complex high-order equations.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324590694&siteId=291194637