# Iterative simultaneous numerical optimization of two functions

p = y 10 - 2 x^2 + 5 x;
q = 20 y x - y^2 + 2 x;


I want to maximize both functions simultaneously (Maximise p to get x and Maximise q to get y). I know that I could use Solve to get the value of x and y i.e.,

Solve[D[p, x] == 0 && D[q, y] == 0, {x, y}]


However, I want to solve it numerically in the iterative way, like this:

1. I will set x=0 and for that x, will maximise q to get y.

2. Now I will set y to the value I obtained from step 1 and maximize p to obtain a new value of x.

3. Again fix the value of x from step 2 and maximize q to get an updated value of y.

4. Repeat this until convergence. I could set a tolerance threshold of e.g. 0.01 as a condition to exit the loop.

I actually have a more complex objective function where I cannot get a closed-form solution. The example above gives a minimal example.

• Possible typo: Should x2 be x^2? Please make sure that p and q are ok. Commented Jul 19, 2022 at 4:43
• Would NSolve or FindRoot not work with the same equation you used in Solve? That way you wouldn't have to set up the iterations yourself. Commented Jul 19, 2022 at 12:46
• Yeah @user293787 it was typo Commented Jul 20, 2022 at 5:02

You may use "FixedPoint" like:

p = y 10 - 2 x^2 + 5 x;
q = 20 y x - y^2 + 2 x;
FixedPoint[( x0 = x /. NMaximize[p /. y -> #[[2]], x][[2]];
y0 = y /. NMaximize[q /. x -> #[[1]], y][[2]]; {x0, y0}) &, {0, 0}]

(* {1.25, 12.5} *)

• Thank you @Daniel. In my case I have a function which is complex in nature and I am not able to get the close form solution. P= (1/(8 d12 (b1+β ρ)2 τ))(a d1 (b1+β ρ)+(b2 (-d1+d2) p2+b1 d1 (-c1+ss)+(-c1 d1-d1 p2+d2 p2+d1 ss) β ρ) τ) (a d1 (b1+β ρ)-(b2 (d1-d2) p2+b1 d1 (c1+3 ss)+(c1 d1+d1 p2-d2 p2+3 d1 ss) β ρ) τ); and Q= P=(1/4) (-2 c ρ2+(a d1 (b1+β ρ)+(b2 (-d1+d2) p2+b1 d1 (-c1+ss)+(-c1 d1-d1 p2+d2 p2+d1 ss) β ρ) τ)2/(d1 (b1+β ρ) τ)); and the decision variable for P is 'ss' and Q is 'ρ'. d1=0.2; Commented Jul 20, 2022 at 5:11
• I have taken the following parameters value d2=0.8; c1=20; c=1; b1=2; b2=1; a=10; p2=1; β=0.2; τ=0.3; Commented Jul 20, 2022 at 5:15
• So I am looking to fetch the value of ss and ρ when the value starts converging which means not much significant improvement in each of the next iteration (can set predefined tolerance level by subtracting the value obtain from last iteration to current iteration.) Commented Jul 20, 2022 at 5:19
• There are undefined parameters: d12, d1,b1,.... Commented Jul 20, 2022 at 7:25
• Apologies. It was square. I corrected the function P=1/(8 d1^2 (b1+β ρ)^2 τ) (a d1 (b1+β ρ)+(b2 (-d1+d2) p2+b1 d1 (-c1+ss)+(-c1 d1-d1 p2+d2 p2+d1 ss) β ρ) τ) (a d1 (b1+β ρ)-(b2 (d1-d2) p2+b1 d1 (c1+3 ss)+(c1 d1+d1 p2-d2 p2+3 d1 ss) β ρ) τ) and Q=1/4 (-2 c ρ^2+(a d1 (b1+β ρ)+(b2 (-d1+d2) p2+b1 d1 (-c1+ss)+(-c1 d1-d1 p2+d2 p2+d1 ss) β ρ) τ)^2/(d1 (b1+β ρ) τ)) and the parameters are d1=0.2; d2=0.8; c1=2; c=5; b1=2; b2=1; a=10; p2=1; β=0.2; τ=0.3; Commented Jul 21, 2022 at 11:26