MATLAB Answers

0

Linears equations summation+combination optimization

Asked by Jordan Verhofstadt on 18 Oct 2019
Latest activity Commented on by John D'Errico
on 19 Oct 2019
Hello, I'm trying to create a code which can optimize a function of type :
Where , , a, b are all known constants ; t is the time vector which is given for a certain length ; are both parameters vectors I want to optimize. u() is the heaviside function.
The point is to minimize "subplus(diff(V))" with constraints, in other words minimize the slope of the function while I'm keeping it between two values Vmin and Vmax
In this example (which is the kind not wanted after the optimization) the B and E point's X coordinates are the values in the vector and D, H the . Vmax is equal to 120 and Vmin = 20.
I know the optimization of this function here isn't useful (only need to put all points of and as late as possible) but I did not present you the whole equation to optimize (don't need it).
My problem is where to begin on matlab.. ga, fmincon, fminbnd... How to translate constraints with Vmax and Vmin with matlab. Could someone help ?
Thanks in advance
Edit:
I tried that :
clear;close;clc;
Param=[2.86 148 2 90 120];
t=linspace(1,7000,7000);
conso=Param(1);
Ttour=Param(2);
Travit=Param(3);
Tpit=Param(4);
Reservoir=Param(5);
global t conso Ttour Travit Tpit Reservoir
p1=[];
p2=[];
optim=fmincon(@(p1,p2)ObjFun,[3600,3800],[],[],[],[],[],[],@constraintsFun);
function f_v = ObjFun(p1,p2)
global t conso Ttour Travit Tpit Reservoir
Ess=zeros(1,length(t));
Rem=zeros(1,length(t));
for i=1:length(p1) %conso/Ttour = delta(V) 1/Travit=a Tpit=b
Ess=Ess+conso/Ttour.*(t-p1(i)).*heaviside(t-p1(i))+1/Travit.*(t-(p1(i)+Tpit)).*heaviside(t-(p1(i)+Tpit));
end
for i=1:length(p2)
Rem=Rem+1/Travit.*(t-p2(i)).*heaviside(t-p2(i))+conso/Ttour.*(t-p2(i)).*heaviside(t-p2(i));
end
f_v=subplus(diff(Reservoir-conso/Ttour.*t+Ess-Rem));
end
function [c,ceq]=constraintsFun(p1,p2)
global Reservoir
vol=ObjFun(p1,p2);
for i=1:length(vol)
c=[];
ceq=[6-vol(i),vol(i)-Reservoir];
end
end
But I got
Not enough input arguments.
Error in Volt>ObjFun (line 29)
for i=1:length(p1)
Error in Volt>@(p1,p2)ObjFun
Error in fmincon (line 546)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in Volt (line 23)
optim=fmincon(@(p1,p2)ObjFun,[3600,3800],[],[],[],[],[],[],@constraintsFun);
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
I know the problem comes from the x0 initial point and I suppose it's because p1 and p2 are vectors with variable length but I don't know how to resolve this.
Hope someone can help me.

  1 Comment

P{lease leave answers for actual answers, not comments, or additional information. I moved your addendum into your question.

Sign in to comment.

Products


Release

R2018b

0 Answers