Matrix Optimization using optimization toolbox - "Objective must be a scalar OptimizationExpression or a struct containing a scalar OptimizationExpression."
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Samuele Bolotta
el 13 de Feb. de 2021
Comentada: Samuele Bolotta
el 13 de Feb. de 2021
Hello everyone,
My task is to find x and y so that if I multiply them by G_max_chl2 and G_max_glu2 (two scalar values that I pre-defined in previous parts of the code) respectively, this:
((G_max_chl2 * x) .* (1 - exp(-t / tau_rise_In2)) .* (exp(-t / tau_decay_In2)) * (Vm - EChl2)) + ((G_max_glu2 * y) .* (1 - exp(-t / tau_rise_Ex2)) .* exp(-t / tau_decay_Ex2) * (Vm - EGlu2))
becomes the same as this:
((G_max_chl) .* (1 - exp(-t / tau_rise_In)) .* (exp(-t / tau_decay_In)) * (Vm - EChl)) + (G_max_glu .* (1 - exp(-t / tau_rise_Ex)) .* exp(-t / tau_decay_Ex) * (Vm - EGlu))
1 All the variables above are the same for the two equations, except for the four "G_max" values. The only two variables that change are G_max_chl2 and G_max_glu2, indeed.
2 Some of these variables are matrices, but again they are not affected by the optimization problem and should remain the same, while the two scalars G_max_chl2 and G_max_glu2 should change
prob = optimproblem('ObjectiveSense','min');
x = optimvar('x',1);
y = optimvar('y',1);
expr = ((G_max_chl2 * x) .* (1 - exp(-t / tau_rise_In2)) .* ...
(exp(-t / tau_decay_In2)) * (Vm - EChl2)) + ((G_max_glu2 * y) .* ...
(1 - exp(-t / tau_rise_Ex2)) .* exp(-t / tau_decay_Ex2) * (Vm - EGlu2)) == ((G_max_chl) .* ...
(1 - exp(-t / tau_rise_In)) .* (exp(-t / tau_decay_In)) * ...
(Vm - EChl)) + (G_max_glu .* (1 - exp(-t / tau_rise_Ex)) .* exp(-t / tau_decay_Ex) * (Vm - EGlu));
prob.Objective = expr;
% Create constraints in the problem
cons1 = ((G_max_chl2 * x) .* (1 - exp(-t / tau_rise_In2)) .* ...
(exp(-t / tau_decay_In2)) * (Vm - EChl2)) + ((G_max_glu2 * y) .* ...
(1 - exp(-t / tau_rise_Ex2)) .* exp(-t / tau_decay_Ex2) * (Vm - EGlu2)) - ((G_max_chl) .* ...
(1 - exp(-t / tau_rise_In)) .* (exp(-t / tau_decay_In)) * ...
(Vm - EChl)) + (G_max_glu .* (1 - exp(-t / tau_rise_Ex)) .* exp(-t / tau_decay_Ex) * (Vm - EGlu)) < 0.1;
cons2 = ((G_max_chl2 * x) .* (1 - exp(-t / tau_rise_In2)) .* ...
(exp(-t / tau_decay_In2)) * (Vm - EChl2)) + ((G_max_glu2 * y) .* ...
(1 - exp(-t / tau_rise_Ex2)) .* exp(-t / tau_decay_Ex2) * (Vm - EGlu2)) - ((G_max_chl) .* ...
(1 - exp(-t / tau_rise_In)) .* (exp(-t / tau_decay_In)) * ...
(Vm - EChl)) + (G_max_glu .* (1 - exp(-t / tau_rise_Ex)) .* exp(-t / tau_decay_Ex) * (Vm - EGlu)) > -0.1;
prob.Constraints.cons1 = cons1;
prob.Constraints.cons2 = cons2;
[sol,fval,exitflag,output] = solve(prob);
I am not sure what is not working. Thanks!
0 comentarios
Respuesta aceptada
Matt J
el 13 de Feb. de 2021
Editada: Matt J
el 13 de Feb. de 2021
You do not have a minimization problem. You just have a system of equations that you are trying to solve. For that, you would use the EquationProblem framework.
x = optimvar('x',1);
y = optimvar('y',1);
expr = ((G_max_chl2 * x) .* (1 - exp(-t / tau_rise_In2)) .* ...
(exp(-t / tau_decay_In2)) * (Vm - EChl2)) + ((G_max_glu2 * y) .* ...
(1 - exp(-t / tau_rise_Ex2)) .* exp(-t / tau_decay_Ex2) * (Vm - EGlu2)) == ((G_max_chl) .* ...
(1 - exp(-t / tau_rise_In)) .* (exp(-t / tau_decay_In)) * ...
(Vm - EChl)) + (G_max_glu .* (1 - exp(-t / tau_rise_Ex)) .* exp(-t / tau_decay_Ex) * (Vm - EGlu));
% Create constraints in the problem
cons1 = ((G_max_chl2 * x) .* (1 - exp(-t / tau_rise_In2)) .* ...
(exp(-t / tau_decay_In2)) * (Vm - EChl2)) + ((G_max_glu2 * y) .* ...
(1 - exp(-t / tau_rise_Ex2)) .* exp(-t / tau_decay_Ex2) * (Vm - EGlu2)) - ((G_max_chl) .* ...
(1 - exp(-t / tau_rise_In)) .* (exp(-t / tau_decay_In)) * ...
(Vm - EChl)) + (G_max_glu .* (1 - exp(-t / tau_rise_Ex)) .* exp(-t / tau_decay_Ex) * (Vm - EGlu)) < 0.1;
cons2 = ((G_max_chl2 * x) .* (1 - exp(-t / tau_rise_In2)) .* ...
(exp(-t / tau_decay_In2)) * (Vm - EChl2)) + ((G_max_glu2 * y) .* ...
(1 - exp(-t / tau_rise_Ex2)) .* exp(-t / tau_decay_Ex2) * (Vm - EGlu2)) - ((G_max_chl) .* ...
(1 - exp(-t / tau_rise_In)) .* (exp(-t / tau_decay_In)) * ...
(Vm - EChl)) + (G_max_glu .* (1 - exp(-t / tau_rise_Ex)) .* exp(-t / tau_decay_Ex) * (Vm - EGlu)) > -0.1;
prob = eqnproblem;
prob.Equations.eqn1=expr;
prob.Equations.eqn2 = cons1;
prob.Equations.eqn3 = cons2;
sol= solve(prob);
3 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Linear Least Squares en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!