Maximum of a sin \sin and cos \cos combo

Calculus Level pending

Numerically find the maximum of

( 12 + 4 cos α + 7 cos β ) 2 + ( 5 + 3 sin α + 4 sin β ) 2 (12 + 4 \cos \alpha + 7 \cos \beta )^2 + (-5 + 3 \sin \alpha + 4 \sin \beta)^2

Inspiration


The answer is 560.1.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Piotr Idzik
Dec 11, 2020

I used simulated annealing and the function provided in the python module scipy.optimize.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding: utf-8 -*-
"""
solution of:
    https://brilliant.org/problems/maximum-of-a-sin-and-cos-combo/
"""

import scipy.optimize
import numpy


def get_val(in_vec):
    """
    returns the value of the function from:
        https://brilliant.org/problems/maximum-of-a-sin-and-cos-combo/
    """
    alpha = in_vec[0]
    beta = in_vec[1]
    val_a = 12+4*numpy.cos(alpha)+7*numpy.cos(beta)
    val_b = -5+3*numpy.sin(alpha)+4*numpy.sin(beta)
    return val_a**2+val_b**2


LOWER = [0]*2
UPPER = [2*numpy.pi]*2
RES = scipy.optimize.dual_annealing(
    lambda x: -get_val(x),
    bounds=list(zip(LOWER, UPPER)),
    maxiter=10000)
print(-RES.fun)

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...