MATLAB: Change Value during optimization process

fminconloopMATLAB and Simulink Student Suiteoptimizationvariables

Hey,
is it possible to change a value during the optimization loop?
Example: I want to maximize x and y
lb = lowerbound ub = upperbound
a = lb(0) ub(100)
b = lb(0) ub(50)
x = a+b
y = a+b
To archieve the solution I need the solution to be x = 50 + 25 and y = 50 + 25 how would i express this in code? Thanks!
example code I thought of but doesnt work
xyprob = optimproblem;
a = optimvar('a','LowerBound',0,'UpperBound',500);
b = optimvar('b','LowerBound',0,'UpperBound',100);
y = optimvar('y');
x = optimvar('x');
xyprob.ObjectiveSense = 'maximize';
xyprob.Objective = x
xyprob.Objective = y
xyprob.Constraints.econs1 = x == a+b
xyprob.Constraints.econs2 = y == a+b
[xysol,fval] = solve(xyprob);
tbl = struct2table(xysol)

Best Answer

How about this?
xyprob = optimproblem;
xa = optimvar('xa','LowerBound',0,'UpperBound',100);
xb = optimvar('xb','LowerBound',0,'UpperBound',50);
ya = optimvar('ya','LowerBound',0,'UpperBound',100);
yb = optimvar('yb','LowerBound',0,'UpperBound',50);
xyprob.ObjectiveSense = 'maximize';
xyprob.Objective = xa+xb;
xyprob.Constraints.econs1 = xa+ya <= 100;
xyprob.Constraints.econs2 = xb+yb <= 50;
xyprob.Constraints.econs3 = xa+xb == ya+yb;
xyprob.Constraints.econs4 = xa+xb + ya+yb == 150;
[xysol,fval] = solve(xyprob);
tbl = struct2table(xysol)