How can I find the maximum of sin(x) through matlab on an interval?

Using just if statements, I need to find the maximum point of sin(x) on a closed interval (a,b). I know to check for if either sin(a) or sin(b) is 1. I also know that if b-a is greater than 2 pi, the maximum would be 1.

If none of these statements are true, I can't figure out how to check for if the equation has a value of 1 between those points through just if statements.

Answers


First check for the (b-a) > 2pi.

Then you could use the fact that the derivative of sine is cosine. Hence if cos(a) is positive and cos(b) is negative you have peak in between, if cos(a) is negative & cos(b) positive its a valley. If cos(a) and cos(b) are same sign, then check if (b-a) > pi to figure if you have a peak. Last it's sin(a) vs sin(b).

Makes sense? :)


Having a, calculate the next point with sin(x)==1. Then compare x with b to check if 1 is within your interval.

Steps to do so:

  1. subtract shift
  2. divide by 2 pi
  3. round up, we want a maximum right to a
  4. reverse 2 and 1

.

candidate=(ceil((a-pi/2)/pi/2)*pi*2)+pi/2
if candidate<b
   candidate is maximum

Need Your Help

In a linux kernel mode, how can I detect a process?

c linux linux-kernel kernel

I need to create a user-mode process. This process has to be detected in kernel mode to be sent to a FIFO queue (SCHED_FIFO) in the Linux kernel.

Problems utilizing MSSQL driver for PHP

php sql-server

I have installed MSSQL driver on PHP , when I check my phpinfo page it surely shows me SQLSVR ENABLE. then even when i try to connect to any SQL Server database it says function does not exist.