Ask Question
27 July, 20:28

3. mydetecttop (f, a, t) which takes three inputs: [50 pts] f: A function handle. a: A real number. t: A real number. Note: You may assume that f is increasing at x = a but there is a cutoff x = b > a after which f starts decreasing. Does: Uses a while loop to check f (x) for x = a, x = a + 3t, x = a + 6t, ... until a value is smaller than the previous value. Returns: The x value (not the f (x) value!) for which this happens

+1
Answers (1)
  1. 27 July, 22:54
    0
    function n = mydetecttop (f, a, t)

    n = a;

    value1 = f (n);

    i1 = 4;

    while (true)

    n = a + i1*t;

    value2 = f (n);

    if (value2 < value1)

    break

    end

    value1 = value2;

    i1 = i1 + 4;

    end

    end

    function t = atc (n)

    if (n<25)

    t = n + 1;

    else

    t = 0 - n;

    end

    end

    f = @atc;

    n = mydetecttop (f, 1, 2)

    Explanation:

    Run a while loop until the required value is found and update the value of the variable n. Check if value2 is less than value1 and then break out of the loop. Update the value of the variable i1 by adding 4. Finally test the mydetecttop (f, a, t) function.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “3. mydetecttop (f, a, t) which takes three inputs: [50 pts] f: A function handle. a: A real number. t: A real number. Note: You may assume ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers