Answer :
Answer:
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.