For a simple question about the dichotomy in C, I would like to point out the words

Updated on technology 2024-02-09
8 answers
  1. Anonymous users2024-02-06

    According to the judgment conditions.

    if(d>0)b=c;

    if(d<0)a=c;

    if(d=0)break

    It can be known that if d is constant, then this judgment is useless, so it should be put inside, put in.

    c=(a+b)/2;Let's just do it. The encoding I modified is as follows:

    #include

    #include

    main()

    double a=,b=,c,d;

    while(fabs(d)>10e-7)

    c=(a+b)/2;

    d=2*c*c*c-4*c*c+3*c-6;

    if(d>0)b=c;

    if(d<0)a=c;

    printf("gen=%.3lf",c);

    I ran it and the result was:

    gen= any key to continue

  2. Anonymous users2024-02-05

    1. Open the Python development tool Idle and create a new '.

    2. F5 runs the program, list1 is sorted correctly, the purpose of writing this is to show that the binary search must be premised on an ordered list, if it is out of order at the beginning, it must be sorted first, when the amount of data is large, quick sort is a good choice, and then perform a dichotomy search.

    3. With the idea of recursion, recursion must have an end condition.

    4. if len(li)==1: li length is equal to 1, only compare this list element with the value to be found return li[0]==item.

    5. If len(li)==0: The length of li is equal to 0, and there is still no value at the end of all searches. return false.

    6. Add the main method to the program.

    7. F5 runs the program, and prints out the dichotomy search result correctly, false true.

  3. Anonymous users2024-02-04

    1. What does the dichotomy of functions mean.

    2. What does the dichotomy of painting mean?

    3. What does the philosophical dichotomy mean.

    4. What does the contradictory dichotomy mean?

    1.For the function y=f(x) which is continuous on the interval [a,b] and f(a)·f(b)<0, the method of obtaining the zero approximation of the zero point by continuously dividing the interval where the zero point of the function f(x) is located in two, so that the two endpoints of the interval are gradually approaching the zero point, and then obtaining the zero approximation is called the dichotomous method.

    2.The bisection method is the method of dividing into two. Let [a,b] be the closed interval of r.

    The successive dichotomy is to create the following interval sequence ([an,bn]): a0=a, b0=b, and for any natural number n, [an+1, bn+1] is equal to [an, cn], or equal to [cn, bn], where cn denotes the midpoint of [an, bn].

  4. Anonymous users2024-02-03

    The worst-case scenario should be log2n rounded down +1, which is also the height of the tree that is halved to find the decision tree (full binary tree).

    First, the topic is not rigorous, this half-fold search can be rounded up or down (most reference books use rounding down by default), rounding down is of course taking 4 times to find 8, and rounding up is 3 times.

    Second, when there is a number left at the end, that number still needs to be compared, from the ** level, you can't simply think that the last remaining number is the number you are looking for, because that number may not be in the sequence, so the last time should also be compared. The decision tree is also defined in this way, and the tree height of the layer in which the number is searched is the number of comparisons.

    As for that conclusion, the number of comparisons that need to be made in the worst case is just an equivalent infinitesimal conclusion. Since the number of comparisons is an integer, the result may be a decimal, and if that is the specific answer to the worst number of comparisons, it will also indicate whether it is rounded up or down.

  5. Anonymous users2024-02-02

    In general, for the function f(x), if there is a real number c, when x=c f(c)=0, then x=c is called the zero point of the function f(x).

    Solving the equation requires all zeros of f(x).

    First find a, b, so that f(a), f(b) different sign, indicating that there must be zero points in the interval (a, b), and then find f[(a+b) 2], now assume f(a)<0, f(b)>0, a if f[(a+b) 2]=0, the point is zero, if f[(a+b) 2]<0, then there is zero point in the interval ((a+b) 2,b), (a+b) 2=>a, continue to use from .

    Judgment of the value of the midpoint function.

    If f[(a+b) 2]>0, then there is zero in the interval (a,(a+b) 2), (a+b) 2=>b, continue from .

    Judgment of the value of the midpoint function.

    In this way, it is possible to keep getting closer to the zero point.

    Like asking: |f(x)|<10^-5 f(x)=2x^3-4x^2+3x-6

    #include"iostream"

    #include""

    #include""

    #define null 0

    double fx(double);f(x) function.

    void main()

    while(fx(xa)*fx(xb)>=0);Determine whether the input range contains a function value of 0

    doelse

    while(fx(xc)>pow(,-5)||fx(xc)<-1*pow(,-5));Determine if the x-root is within the exact range close to the function value of 0.

    printf("The resulting number is: %f",xc);

    double fx(double x)

  6. Anonymous users2024-02-01

    This ** is the numerical solution to solving the root of the equation f(x)=0 in the interval [-10,10].

    The idea of the method is: always select the value in the middle of the interval, if you find the value of the function in the middle and the value of the function on one side, the different sign, then the solution in this smaller interval, using eps=1e-5 as the limit size of the interval, through the iterative method to solve the numerical solution of the equation.

    So knowing the above thoughts, then else

    if(f(a)*f(c)<0)

    b=c;Illustrated.

    f(a) and f(c) different signs, then use b=(a+b) 2 to narrow the iteration interval and continue iteration; The same goes for else

    a=c;If f(a) and f(c) have the same sign, then use a(a+b) 2 to narrow down the iteration interval and continue iteration!

  7. Anonymous users2024-01-31

    Use the dichotomy to find the root of the following equation between (-10,10). 2x3-4x2+3x-6=0 [Hint] (1) Take two different points x1 and x2, if the symbols of f(x1) and f(x2) are opposite, then there must be a root (the intersection of the curve and the x-axis) in the (x1, x2) interval. If f(x1) and f(x2) have the same symbol, x1 and x2 should be changed until f(x1) and f(x2) are heterogeneous.

    Note that the values of x1 and x2 should not differ too much to ensure that there is only one (x1, x2) interval.

    2) The midpoint between x1 and x2 x=(x1+x2) 2, see Figure 4-1, and then find the function value f(x) from x.

    3) If f(x) and f(x1) have the same symbol, then the root must be in the interval (x,x2), and x will be the new x1; If f(x) is the same symbol as f(x2), it means that the root is in the interval (x1,x), and x is the new x2.

    4) Repeat steps (2) and (3) until |f(x)|So far, is a very small number. In this case, f(x) 0 is considered to be the root.

    #include

    #include

    double fun(double x)

    double root(double a, double b, double e)

    while(fabs(y) >e);

    return x;

    int main(void)

  8. Anonymous users2024-01-30

    The 2-point method is also called the 2-point search method, which is also called the fold half method.

    But the condition is that the data you're looking for must be in order! A sequential storage structure must be employed.

    The advantages of the split search method are that the number of comparisons is less, the search speed is fast, and the average performance is good. The disadvantage is that the table to be looked up is required to be an ordered table, and it is difficult to insert and delete. Therefore, the half-fold search method is suitable for finding ordered lists that do not change frequently and find them frequently.

    Firstly, the keywords recorded in the middle of the table are compared with the lookup keywords, and if the two are equal, the lookup is successful. Otherwise, the intermediate position record is used to divide the table into two subtables, the first and last subtables, if the keyword of the intermediate location record is greater than the search keyword, the previous subtable is further searched, otherwise the next subtable is further searched.

    Repeat the above process until a record that satisfies the criteria is found, making the lookup successful, or until the child table does not exist, in which case the lookup is unsuccessful.

    Write a paragraph** You see.

    intsearchdata(int

    des,int

    min,int

    max) *where min is the minimum subscript coordinate, max is the maximum subscript coordinates, and des is the subscript of the value to be found*

    intmid=0;

    mid=(min+max)/2;mid takes the subscript of the middle value of the array you are looking for.

    while(mindes) if greater than des.

    max=mid-1;The maximum subscript is equal to the current submark -1, which means that the search range is narrowed.

    elsemin=mid+1;Otherwise, the minimum value of the subscript coordinate +1 narrows the search range.

Related questions
6 answers2024-02-09

Understand the following rules: 1) Overloading an operator does not change the priority of the operator. >>>More

6 answers2024-02-09

Define the struct:

typedef struct _legaladdress_{ >>>More

9 answers2024-02-09

Scope. You static char *chh;

static char *ch1;Although the address pointed to by the two pointers does not change, have you ever wondered whether the memory address they point to has been released, char chc[10]; It's local, the function is out, the lifecycle is over, and you're trying to access it with a pointer in void times(). >>>More

4 answers2024-02-09

Just take a look at this one**.

Hope it helps. >>>More

7 answers2024-02-09

A local variable (an internal variable) is defined inside a function, and its scope is limited to the variable inside the function that defines it. >>>More