Algorithm for Finding the approximate root-MATLAB implementation

Source: Internet
Author: User

In numerical calculation, it is very important to obtain the approximation of a root, because when using other methods such as Newton iteration, we often need to find an initial point, the initial vertex should be selected near the root. In addition, only when the approximate root is known can the overall conversion be local. I have just learned the numerical calculation method and have a limited understanding. Let's discuss it together.

Function file approot_my.m

Function r = approot_my (f, x, epsilon)
Y = f (x );
Yrange = max (y)-min (y );
Epsilon2 = yrange * Epsilon; % the description of Y is very small, that is, the vertex tangent to the X axis.
N = length (X );
M = 0;
X (n + 1) = x (n );
Y (n + 1) = y (N );
K = 2;
While k <= N
If (Y (k-1) * Y (k) <= 0)
M = m + 1;
R (m) = (x (k-1) + x (k)/2;
End
S = (Y (k)-y (k-1) * (Y (k + 1)-y (k); % Y Curve Inflection Point
If (ABS (Y (k) <epsilon2) & (S <= 0)
M = m + 1;
R (m) = x (k );
End
K = k + 1;
End

Test function F. M

Function Y = f (x)
Y = sin (COS (X. ^ 3 ));

Run

> X =-. 000;
> Approot_my (@ f, x, 0.001)

Ans =

-1.9878-1.6766-1.1625 1.1625 1.6766

The following figure shows the test function.

> X =-. 000;
> Y = sin (COS (X. ^ 3 ));
> Plot (X, Y, X, 0)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.