Items tagged with optimization optimization Tagged Items Feed

Dear all

is it possible to solve bilevel optimization problems in maple?

            min F(x,y)

     s.t.    min G(x,y)

        s.t.   k(x,y)<=0

As I am trying to solve this integration:

restart; with(linalg); with(stats); with(plots); with(Statistics); with(LinearAlgebra); with(Optimization);
lambda0 := proc (t) options operator, arrow; gamma0+gamma1*t+gamma2*t^2 end proc;
lambda := lambda0(t)*exp(beta*s);
t1 := 145; t3 := 250; t2 := (t1+t3)*(1/2);
s := 1/(273.16+50); s1 := 1/(273.16+t1); s3 := 1/(273.16+t3); s2 := 1/(273.16+t2); gamma0 := 0.1e-3; gamma1 := .5; gamma2 := 0; beta := -3800;
c := 300; n := 200;
Theta := solve(1-exp(-(gamma0*tau1+(1/2)*gamma1*tau1^2+(1/3)*gamma2*tau1^3)*exp(beta*s1)) = 1-exp(-(gamma0*a+(1/2)*gamma1*a^2+(1/3)*gamma2*a^3)*exp(beta*s2)), a);

a := Theta[1];

Delta := solve(1-exp(-(gamma0*(a+tau2-tau1)+(1/2)*gamma1*(a+tau2-tau1)^2+(1/3)*gamma2*(a+tau2-tau1)^3)*exp(beta*s2)) = 1-exp(-(gamma0*b+(1/2)*gamma1*b^2+(1/3)*gamma2*b^3)*exp(beta*s3)), b);

b := Delta[1];

A1 := `assuming`([unapply(int(exp(beta*s1)*exp(-(gamma0*t+(1/2)*gamma1*t^2+(1/3)*gamma2*t^3)*exp(beta*s1))/(gamma0+gamma1*t+gamma2*t^`2`), t = N .. M), N, M)], [N > 0, M > 0]);
A2 := unapply(int(exp(beta*s2)*exp(-(gamma0*(a+t-tau1)+(1/2)*gamma1*(a+t-tau1)^2+(1/3)*gamma2*(a+t-tau1)^3)*exp(beta*s2))/(gamma0+gamma1*(a+t-tau1)+gamma2*(a+t-tau1)^2), t = N .. M), N, M);
A3 := unapply(int(exp(beta*s3)*exp(-(gamma0*(b+t-tau2)+(1/2)*gamma1*(b+t-tau2)^2+(1/3)*gamma2*(b+t-tau2)^3)*exp(beta*s3))/(gamma0+gamma1*(b+t-tau2)+gamma2*(b+t-tau2)^2), t = N .. M), N, M);
B1 := `assuming`([unapply(int(t^2*exp(beta*s1)*exp(-(gamma0*t+(1/2)*gamma1*t^2+(1/3)*gamma2*t^3)*exp(beta*s1))/(gamma2*t^2+gamma1*t+gamma0), t = N .. M), N, M)], [N > 0, M > 0]);
B2 := unapply(int((a+t-tau1)^2*exp(beta*s2)*exp(-(gamma0*(a+t-tau1)+(1/2)*gamma1*(a+t-tau1)^2+(1/3)*gamma2*(a+t-tau1)^3)*exp(beta*s2))/(gamma0+gamma1*(a+t-tau1)+gamma2*(a+t-tau1)^2), t = N .. M), N, M);
B3 := unapply(int((b+t-tau2)^2*exp(beta*s3)*exp(-(gamma0*(b+t-tau2)+(1/2)*gamma1*(b+t-tau2)^2+(1/3)*gamma2*(b+t-tau2)^3)*exp(beta*s3))/(gamma0+gamma1*(b+t-tau2)+gamma2*(b+t-tau2)^2), t = N .. M), N, M);

F0 := A1(0, tau1)+A2(tau1, tau2)+A3(tau2, c);
F1 := B1(0, tau1)+B2(tau1, tau2)+B3(tau2, c);

NLPSolve(1/(n^3*(F0*F1-F1)), tau1 = 115 .. 201, tau2 = 237 .. 273);

I need to have tau1 tau2 as varibles to get there optimal values ..

But this error keeps coming :


Error, (in Optimization:-NLPSolve) integration range or variable must be specified in the second argument, got HFloat(1.0) = HFloat(158.0) .. HFloat(255.0)

Please Help ..

As am trying to solve this integration:


A(c,n,m):=evalf(int(1/(y)*exp(-c*y^(2)),y=n..m))

B(c,n,m):=evalf(int(exp(-c*y^(2)),y=n..m))

C(c,n,m):=evalf(int(y*exp(-c*y^(2)),y=n..m))

d(c,n,m):=evalf(int(y^(2)*exp(-c*y^(2)),y=n..m))

E(c,n,m):=evalf(int(y^(3)*exp(-c*y^(2)),y=n..m))

F0 := exp(beta*s1)*exp(gamma0^2*exp(beta*s1)/(2*gamma1))*A((1/2)*gamma1*exp(beta*s1), gamma0/gamma1,gamma0/gamma1+tau1)/gamma1+exp(beta*s2)*exp(gamma0^2*exp(beta*s2)/(2*gamma1))*A((1/2)*gamma1*exp(beta*s2), gamma0/gamma1+a, gamma0/gamma1+tau2-tau1+a)/gamma1+exp(beta*s3)*exp(gamma0^2*exp(beta*s3)/(2*gamma1))*A((1/2)*gamma1*exp(beta*s3), gamma0/gamma1+b, gamma0/gamma1+c-tau2+b)/gamma1

F1 := exp(beta*s1)*exp(gamma0^2*exp(beta*s1)/(2*gamma1))*(gamma0^2*A((1/2)*gamma1*exp(beta*s1), gamma0/gamma1, gamma0/gamma1+tau1)/gamma1^2-2*gamma0*B((1/2)*gamma1*exp(beta*s1), gamma0/gamma1, gamma0/gamma1+tau1)/gamma1+C((1/2)*gamma1*exp(beta*s1), gamma0/gamma1, gamma0/gamma1+tau1))/gamma1+exp(beta*s2)*exp(gamma0^2*exp(beta*s2)/(2*gamma1))*(gamma0^2*A((1/2)*gamma1*exp(beta*s2), gamma0/gamma1+a, gamma0/gamma1+tau2-tau1+a)/gamma1^2-2*gamma0*B((1/2)*gamma1*exp(beta*s2), gamma0/gamma1+a, gamma0/gamma1+tau2-tau1+a)/gamma1+C((1/2)*gamma1*exp(beta*s2), gamma0/gamma1+a, gamma0/gamma1+tau2-tau1+a))/gamma1+exp(beta*s3)*exp(gamma0^2*exp(beta*s3)/(2*gamma1))*(gamma0^2*A((1/2)*gamma1*exp(beta*s3), gamma0/gamma1+b, gamma0/gamma1+c-tau2+b)/gamma1^2-2*gamma0*B((1/2)*gamma1*exp(beta*s3), gamma0/gamma1+b, gamma0/gamma1+c-tau2+b)/gamma1+C((1/2)*gamma1*exp(beta*s3), gamma0/gamma1+b, gamma0/gamma1+c-tau2+b))/gamma1

F01 := exp(beta*s1)*exp(gamma0^2*exp(beta*s1)/(2*gamma1))*(B((1/2)*gamma1*exp(beta*s1), gamma0/gamma1, gamma0/gamma1+tau1)-gamma0*A((1/2)*gamma1*exp(beta*s1), gamma0/gamma1, gamma0/gamma1+tau1)/gamma1)/gamma1+exp(beta*s2)*exp(gamma0^2*exp(beta*s2)/(2*gamma1))*(B((1/2)*gamma1*exp(beta*s2), gamma0/gamma1+a, gamma0/gamma1+tau2-tau1+a)-gamma0*A((1/2)*gamma1*exp(beta*s2), gamma0/gamma1+a, gamma0/gamma1+tau2-tau1+a)/gamma1)/gamma1+exp(beta*s3)*exp(gamma0^2*exp(beta*s3)/(2*gamma1))*(B((1/2)*gamma1*exp(beta*s3), gamma0/gamma1+b, gamma0/gamma1+c-tau2+b)-gamma0*A((1/2)*gamma1*exp(beta*s3), gamma0/gamma1+b, gamma0/gamma1+c-tau2+b)/gamma1)/gamma1

`F&beta;` := int((s1^2*(gamma0*t+(1/2)*gamma1*t^2)*exp(beta*s1)*(gamma1*t+gamma0)*exp(beta*s1))*exp(-(gamma0*t+(1/2)*gamma1*t^2)*exp(beta*s1)), t = 0 .. tau1)+int((s2^2*(gamma0*(a+t-tau1)+(1/2)*gamma1*(a+t-tau1)^2)*exp(beta*s2)*(gamma0+gamma1*(a+t-tau1))*exp(beta*s2))*exp(-(gamma0*(a+t-tau1)+(1/2)*gamma1*(a+t-tau1)^2)*exp(beta*s2)), t = tau1 .. tau2)+int((s3^2*(gamma0*(b+t-tau2)+(1/2)*gamma1*(b+t-tau2)^2)*exp(beta*s3)*(gamma0+gamma1*(b+t-tau2))*exp(beta*s3))*exp(-(gamma0*(b+t-tau2)+(1/2)*gamma1*(b+t-tau2)^2)*exp(beta*s3)), t = tau2 .. c)+int((s3^2*(gamma0*(b+t-tau2)+(1/2)*gamma1*(b+t-tau2)^2)*exp(beta*s3)*(gamma0+gamma1*(b+t-tau2))*exp(beta*s3))*exp(-(gamma0*(b+t-tau2)+(1/2)*gamma1*(b+t-tau2)^2)*exp(beta*s3)), t = c .. infinity)

I need to have tau2 as varibles to get there optimal values ..

Minimize(1/((F0*F1-F01^2)*n^3*`F&beta;`), tau2 = 237..273})

But this error keeps coming :

Error, (in Optimization:-NLPSolve) integration range or variable must be specified in the second argument, got HFloat(1.0) = 121.0828419 .. HFloat(193.0828419)

Please Help ..

Hi all

 

I am trying to maximize a function f(x,y,z,w) in terms of x. (Only x is treated as a variable, and the others are treated as parameters).

However, all I know is that y,z,w they are parameters and they are non-negative. I have already tried with the "optmization help page" from maplesoft's website, and it looks like it will search the range of x,y,z,w, and it will return numerical values at which this function is maximized. 

 

 

However, what I want is instead a close-form solution of x=g(y,z,w) that will maximize the function.   In other words, I would like to keep the parameter in symbolic forms. 

 

Can Maple do that?

Hi,

On page 32 (PDF)

 

Two different results were obtained using the Global optimization.

Log likelihood does not differ much. BUT the estimates vary a lot, such as mu[p].

tmp.mw

tmp.pdf

 

When I tried to use one of the answer from a particular run, I get the HFLOATING error, see picture.

So how reliable is this? Could there be a better way to optimize this ?

 

Thanks!

 

As an additional note, if I have Matlab R2014a, could I use Matlab to optimize the target function? DO I need to purchase a seperate addon?

 

hi all.

I have wrore the following program for optimization with bernstein and block pulse hybrid functions.

the program have some errors which i can't understand.

Bernestien1.mws

restart:

alias(C=binomial):
with(LinearAlgebra):
macro(LA= LinearAlgebra):


HybrFunc:=proc(N, M,  tj)               # N=Number of subintervals,  M=Number of functions in subintervals
 
local B, n, m;

global b;

for n from 1 to N do
for m from 0 to M-1 do

B := (i,m,t) -> C(m,i)*(1-t)^(m-i)*t^i:

b[n,m]:=unapply(piecewise(t>=(n-1)*tj/N and t<n*tj/N, B(m,2,N*t-(n-1)*tj), 0), t):
 od:od:


Array(1..N, 0..M-1, (n,m)->b[n,m](t)):

#convert(%,vector);
end proc:

HybrFunc(3, 3, 1);




                                       # End Of Definition
 
g2(t):=t;            #*exp(t-1):                      # Any other function can be replaced here
    

g1(t):=add(add(c[n,m]*b[n,m](t), m=0..2), n=1..3);
Optimization[Minimize](sqrt(int((g2(t)-g1(t))^2, t=0.. 1)));
assign(op(%[2]));
plot([g2(t),g1(t)], t=0..1, 0..5, color=[blue,red],thickness=[1,3],discont, scaling=constrained);

Array(1 .. 3, 0 .. 2, {(1, 0) = piecewise(0 <= t and t < 1/3, (1-3*t)^2, 0), (1, 1) = piecewise(0 <= t and t < 1/3, (6*(1-3*t))*t, 0), (1, 2) = piecewise(0 <= t and t < 1/3, 9*t^2, 0), (2, 0) = piecewise(1/3 <= t and t < 2/3, (2-3*t)^2, 0), (2, 1) = piecewise(1/3 <= t and t < 2/3, (2*(2-3*t))*(3*t-1), 0), (2, 2) = piecewise(1/3 <= t and t < 2/3, (3*t-1)^2, 0), (3, 0) = piecewise(2/3 <= t and t < 1, (3-3*t)^2, 0), (3, 1) = piecewise(2/3 <= t and t < 1, (2*(3-3*t))*(3*t-2), 0), (3, 2) = piecewise(2/3 <= t and t < 1, (3*t-2)^2, 0)}, datatype = anything, storage = rectangular, order = Fortran_order)

g2(t) := t

"g1(t):=c[1,0] ({[[(1-3 t)^2,0<=t and t<1/3],[0,otherwise]])+c[1,1] ({[[6 (1-3 t) t,0<=t and t<1/3],[0,otherwise]])+c[1,2] ({[[9 t^2,0<=t and t<1/3],[0,otherwise]])+c[2,0] ({[[(2-3 t)^2,1/3<=t and t<2/3],[0,otherwise]])+c[2,1] ({[[2 (2-3 t) (3 t-1),1/3<=t and t<2/3],[0,otherwise]])+c[2,2] ({[[(3 t-1)^2,1/3<=t and t<2/3],[0,otherwise]])+c[3,0] ({[[(3-3 t)^2,2/3<=t and t<1],[0,otherwise]])+c[3,1] ({[[2 (3-3 t) (3 t-2),2/3<=t and t<1],[0,otherwise]])+c[3,2] ({[[(3 t-2)^2,2/3<=t and t<1],[0,otherwise]])"

Error, (in Optimization:-NLPSolve) complex value encountered

Error, invalid left hand side in assignment

(1)



Download Bernestien1.mws

 I'll be so grateful if any one can help me.

Mahmood   Dadkhah

Ph.D Candidate

Applied Mathematics Department

f1 := -2*x1 - x2;
f2 := -x1 - 4*x2;
g1 := 2*x1 + 3*x2 - 6;
g2 := -x1;
g3 := -x2;
penalty := lambda1*Max(f1-M,0)+lambda2*Max(f2-M,0)+(M^2)*(max(g1,0) + max(g2,0) + max(g3,0));
M := 1;
k := 1;
s := 1;
lambda1 := 0.5;
lambda2 := 0.5;
with(Optimization):
Minimize(subs(lambda2=0.5, subs(lambda1=0.5, subs(M=1, penalty))));

correct answer for these parameters should be below, however, Minimize got error

when lambda1 = 0.5, lambda2 = 0.5
(x1, x2) = 1.551123, 0.965918
f(x1, x2) = (–4.068164, –5.414795);

1. how to do optimization with partial differential equation as constraints in maple

2. how to do optimization with  partial differential equation as objective function in order to make output obey this model

Hi, I would like to solve this nonlinear problem :

 

with :

I use the NLPSolve command and i get this error : Error, (in Optimization:-NLPSolve) integer variables are not accepted.

Can you help me ?

 

 

 

 

Hi Maple-Prime-ers!

I have a system of equations, containing 18 variables and 13 equations, making this a 5 degree of freedom (DOF) system.  I would like to analytically solve each of the equations in terms of each of these DOFs.  Normally I would use solve(system, dof_variables) to accomplish this, but it doesn't return anything.  Not even [].

I can solve this system by hand.  I've included a hand-solution involving isolate() and subs() in the attached worksheet.  I'm looking to incorporate this in an optimization algorithm with varying system, so I would like an automated way of doing this.

Does anybody have any suggestions to get solve to work as intended?

 

3driversys_FD_BRAKE_ICE_GEN.mw

 

Here is the system I am talking about:

 

 

The free variables are:  {FD_T, FD_W, ICE_T, EM2_T, BRAKE_T}

 

I'm looking for a solution in this form:

 

 

 

 

 

As am trying to solve this integration:

int(B*eta^(-B)*t^(B-1)*exp(-(t/eta)^B)*(t-n*h), t = n .. (n+1)*h)

where,

ETA:=1000

B:=2.5

But this error keeps coming :

Error, (in Optimization:-NLPSolve) integration range or variable must be specified in the second argument, got 1. = 1. .. 2.

 

Please Help ..

what is the wrong with Pi set ::: in this function ::: Warning, no iterations performed as initial point satisfies first-order conditions

Optimization[Minimize](x^2 + y^2 + 25*(sin(x)^2+sin(y)^2), x=-2*Pi .. 2*Pi , y= -2*Pi .. 2*Pi);

Warning, no iterations performed as initial point satisfies first-order conditions
[0., [x = HFloat(0.0), y = HFloat(0.0)]]


Optimization[Maximize](x^2 + y^2 + 25*(sin(x)^2+sin(y)^2), x=-2*Pi .. 2*Pi , y= -2*Pi .. 2*Pi);

Warning, no iterations performed as initial point satisfies first-order conditions
[-0., [x = HFloat(0.0), y = HFloat(0.0)]]

--------------------------------

I got my good result when I apply it with this function :


f:= (x,y)->cos(x)*sin(y) -(x/(y^2+1));


Optimization[Maximize](f(x,y), x = -1 .. 2, y = -1 .. 1);


[0.994945017202501170,[x = HFloat(-0.6362676080636113), y = HFloat(1.0)]]

Optimization[Minimize](f(x,y), x = -1 .. 2, y = -1 .. 1);


[-2.02180678335978703,[x = HFloat(2.0), y = HFloat(0.10578346945175972)]]

Hi all 

I have the following segment of maple program which belongs to time delay systems dynamic. here C=X-X0-G.Z-X.Dtau.P+X.Dtau.Z-U.P, is a matrix(vector) which comes from reordering the system terms and my goal is to minimizing J:=X.E.Transpose(X)+U.E.Transpose(U), subject to constraint C=0, but i don't know how to do so.

I will be so grateful if anyone can guide me

best wishes

Mahmood   Dadkhah

Ph.D Candidate

Applied Mathematics Department


restart:
with(Optimization):
with(LinearAlgebra):
macro(LA= LinearAlgebra):
L:=1:  r:=2:  tau:= 1:
interface(rtablesize= 2*r+1):

Z:= Matrix(
     2*r+1, 2*r+1,
     [tau,
      seq(evalf((L/(2*(iz-1)*Pi))*sin(2*(iz-1)*Pi*tau/L)), iz= 2..r+1),
      seq(evalf((L/(2*(iz-1-r)*Pi))*(1-cos(2*(iz-1-r)*Pi*tau/L))), iz= r+2..2*r+1)
      ],
     scan= columns,
     datatype= float[8]
);
                        
Dtau00:= < 1 >:
Dtau01:= Vector[row](r):
Dtau02:= Vector[row](r):
Dtau10:= Vector(r):
Dtau20:= Vector(r):

Dtau1:= LA:-DiagonalMatrix([seq(evalf(cos(2*i*Pi*tau/L)), i= 1..r)]):
Dtau2:= LA:-DiagonalMatrix([seq(evalf(sin(2*i*Pi*tau/L)), i= 1..r)]):
Dtau3:= -Dtau2:
Dtau4:= copy(Dtau1):

Dtau:= < < Dtau00 | Dtau01 | Dtau02 >,
         < Dtau10 | Dtau1  | Dtau2  >,
         < Dtau20 | Dtau3  | Dtau4  > >;
 
P00:= < L/2 >:
P01:= Vector[row](r):
P02:= Vector[row](r, j-> evalf(-L/j/Pi), datatype= float[8]):
P10:= Vector(r):
P20:= Vector(r, i-> evalf(L/2/i/Pi)):
P1:= Matrix(r,r):
P2:= LA:-DiagonalMatrix(P20):
P3:= LA:-DiagonalMatrix(-P20):
P4:= Matrix(r,r):

P:= < < P00 | P01 | P02 >,
      < P10 | P1  | P2  >,
      < P20 | P3  | P4  > >;

interface(rtablesize=2*r+1):    # optionally
J:=Vector([L, L/2 $ 2*r]):      # Matrix([[...]]) would also work here

E:=DiagonalMatrix(J);

X:=  Vector[row](2*r+1,symbol=a);
U:=Vector[row](2*r+1,symbol=b);

X0:= Vector[row](2*r+1,[1]);
G:=Vector[row](2*r+1,[1]);
C:=simplify(X-X0-G.Z-X.Dtau.P+X.Dtau.Z-U.P);

Z := Matrix(5, 5, {(1, 1) = 1., (1, 2) = 0., (1, 3) = 0., (1, 4) = 0., (1, 5) = 0., (2, 1) = 0., (2, 2) = 0., (2, 3) = 0., (2, 4) = 0., (2, 5) = 0., (3, 1) = 0., (3, 2) = 0., (3, 3) = 0., (3, 4) = 0., (3, 5) = 0., (4, 1) = 0., (4, 2) = 0., (4, 3) = 0., (4, 4) = 0., (4, 5) = 0., (5, 1) = 0., (5, 2) = 0., (5, 3) = 0., (5, 4) = 0., (5, 5) = 0.})

Dtau := Matrix(5, 5, {(1, 1) = 1, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (2, 1) = 0, (2, 2) = 1., (2, 3) = 0, (2, 4) = 0., (2, 5) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 1., (3, 4) = 0, (3, 5) = 0., (4, 1) = 0, (4, 2) = -0., (4, 3) = -0., (4, 4) = 1., (4, 5) = 0, (5, 1) = 0, (5, 2) = -0., (5, 3) = -0., (5, 4) = 0, (5, 5) = 1.})

P := Matrix(5, 5, {(1, 1) = 1/2, (1, 2) = 0, (1, 3) = 0, (1, 4) = -.318309886100000, (1, 5) = -.159154943000000, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (2, 4) = .1591549430, (2, 5) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0, (3, 5) = 0.7957747152e-1, (4, 1) = .1591549430, (4, 2) = -.159154943000000, (4, 3) = 0, (4, 4) = 0, (4, 5) = 0, (5, 1) = 0.7957747152e-1, (5, 2) = 0, (5, 3) = -0.795774715200000e-1, (5, 4) = 0, (5, 5) = 0})

E := Matrix(5, 5, {(1, 1) = 1, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (2, 1) = 0, (2, 2) = 1/2, (2, 3) = 0, (2, 4) = 0, (2, 5) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 1/2, (3, 4) = 0, (3, 5) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 1/2, (4, 5) = 0, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = 0, (5, 5) = 1/2})

X := Vector[row](5, {(1) = a[1], (2) = a[2], (3) = a[3], (4) = a[4], (5) = a[5]})

U := Vector[row](5, {(1) = b[1], (2) = b[2], (3) = b[3], (4) = b[4], (5) = b[5]})

X0 := Vector[row](5, {(1) = 1, (2) = 0, (3) = 0, (4) = 0, (5) = 0})

G := Vector[row](5, {(1) = 1, (2) = 0, (3) = 0, (4) = 0, (5) = 0})

C := Vector[row](5, {(1) = 1.500000000*a[1]-2.-.1591549430*a[4]-0.7957747152e-1*a[5]-.5000000000*b[1]-.1591549430*b[4]-0.7957747152e-1*b[5], (2) = a[2]+.1591549430*a[4]+.1591549430*b[4], (3) = a[3]+0.7957747152e-1*a[5]+0.7957747152e-1*b[5], (4) = a[4]+.3183098861*a[1]-.1591549430*a[2]+.3183098861*b[1]-.1591549430*b[2], (5) = a[5]+.1591549430*a[1]-0.7957747152e-1*a[3]+.1591549430*b[1]-0.7957747152e-1*b[3]})

(1)

J:=X.E.Transpose(X)+U.E.Transpose(U);

J := a[1]^2+(1/2)*(a[2]^2)+(1/2)*(a[3]^2)+(1/2)*(a[4]^2)+(1/2)*(a[5]^2)+b[1]^2+(1/2)*(b[2]^2)+(1/2)*(b[3]^2)+(1/2)*(b[4]^2)+(1/2)*(b[5]^2)

(2)

Minimize(J,{C=0});






Error, (in Optimization:-NLPSolve) invalid arguments

 

#XP:=-.015+X[1]+add(X[l+1]*f1(l)+X[r+l+1]*f2(l), l= 1..r):
#plot([XP,T1], t= 0..1);#,legend= "Solution Of x(t) with r=50"):

 

 

 

 

 

 

Download work1.mwswork1.mws

Data.xlsx

XY.mw

XYZ.mw

 

Hello,

I'm using the Global Optimization Toolbox to solve some examples and fit equations to a given data, finding "unknown" parameters. I generated the data on Excel, and I already know the values of these parameters.

The XY case is (there is no problem here, I just put as a example I follow):

> with(GlobalOptimization);
> with(plots);

> X := ExcelTools:-Import("F:\\Data.xlsx", "Plan1", "I5:I25");
> Y := ExcelTools:-Import("F:\\Data.xlsx", "Plan1", "J5:J25");

> XY := zip( (X, Y) -> [X, Y] , X, Y);
> fig1 := plot(XY, style = point, view = [.9 .. 3.1, 6 .. 40]);


> Model := A+B*x+C*x^2+D*cos(x)+E*exp(x):
> VarInterv := [A = 0 .. 10, B = 0 .. 10, C = -10 .. 10, D = 0 .. 10, E = 0 .. 10];

> ModelSubs := proc (x, val)

    subs({x = val}, Model)

    end proc;


> SqEr := expand(add((ModelSubs(x, X(i))-Y(i))^2, i = 1 .. 21));
> CoefList := GlobalSolve(SqEr, op(VarInterv), timelimit = 5000);

> Model := subs(CoefList[2], Model):

 

I could find the right values of A, B, C, D and E. 

 

My problem is in the XYZ case, where I don't know how to "write" the right instruction. My last attempt was:

> with(GlobalOptimization);
> with(plots);

> X := ExcelTools:-Import("F:\\Data.xlsx", "Plan1", "Q5:Q25"); X2 := convert(X, list);
> Y := ExcelTools:-Import("F:\\Data.xlsx", "Plan1", "R5:R25"); Y2 := convert(Y, list);
> Z := ExcelTools:-Import("F:\\Data.xlsx", "Plan1", "S5:S25"); Z2 := convert(Z, list);
> NElem := numelems(X);

> pointplot3d(X2, Y2, Z2, axes = normal, labels = ["X", "Y", "Z"], symbol = box, color = red);

 

> Model := A*x+B*y+C*sin(x*y)+D*exp(x/y);

> VarInterv := [A = 0 .. 10, B = 0 .. 10, C = 0 .. 10, D = 0 .. 10];

> ModelSubs:=proc({x,y},val)

subs({(x,y)=val},Model)

end proc:
Error, missing default value for option(s)

> SqEr := expand(add((ModelSubs(x, y, X(i), Y(i))-Z(i))^2, i = 1 .. NElem));
> CoefList := GlobalSolve(SqEr, op(Range), timelimit = 5000);
Error, (in GlobalOptimization:-GlobalSolve) finite bounds must be provided for all variables

 

My actual problem involves six equations, six parameters and four or five independent variables on each equation, but I alread developed a way to solve two or more equations simultaneously.

Thanks

Following my previous question

http://www.mapleprimes.com/questions/200627-Lssolve-Midpoint

I wrote the following code

 

restart:
Phiavg:=0.06;
lambda:=0.05;
Ha:=0;
NBT:=0.5;
Nr:=500;
#N[bt]:=cc*NBT+(1-cc)*4; ## cc between 0 and 1
N[bt]:=cc*NBT+(1-cc^2)*0.75;


                              0.06
                              0.05
                               0
                              0.5
                              500
                                           2
                    0.5 cc + 0.75 - 0.75 cc
eq1:=diff(u(eta),eta,eta)+1/(mu(eta)/mu1[w])*(sigma-Nr*(phi(eta)-phi1[w])-(1-phi(eta))*T(eta)-Ha^2*u(eta))+((1/mu(eta)*(mu_phi*diff(phi(eta),eta)))*diff(u(eta),eta));
eq2:=diff(T(eta),eta)-1/(k(eta)/k1[w]);
eq3:=diff(phi(eta),eta)-phi(eta)/(N[bt]*(1-gama1*T(eta))^2)*diff(T(eta),eta);
 /  d   /  d         \\      1                                 
 |----- |----- u(eta)|| + ------- (mu1[w] (sigma - 500 phi(eta)
 \ deta \ deta       //   mu(eta)                              

    + 500 phi1[w] - (1 - phi(eta)) T(eta)))

             /  d           \ /  d         \
      mu_phi |----- phi(eta)| |----- u(eta)|
             \ deta         / \ deta       /
    + --------------------------------------
                     mu(eta)                
                    /  d         \   k1[w]
                    |----- T(eta)| - ------
                    \ deta       /   k(eta)
                                       /  d         \            
                              phi(eta) |----- T(eta)|            
/  d           \                       \ deta       /            
|----- phi(eta)| - ----------------------------------------------
\ deta         /   /                       2\                   2
                   \0.5 cc + 0.75 - 0.75 cc / (1 - gama1 T(eta))
mu:=unapply(mu1[bf]*(1+a[mu1]*phi(eta)+b[mu1]*phi(eta)^2),eta):
k:=unapply(k1[bf]*(1+a[k1]*phi(eta)+b[k1]*phi(eta)^2),eta):
rhop:=3880:
rhobf:=998.2:
cp:=773:
cbf:=4182:
rho:=unapply(  phi(eta)*rhop+(1-phi(eta))*rhobf ,eta):
c:=unapply(  (phi(eta)*rhop*cp+(1-phi(eta))*rhobf*cbf )/rho(eta) ,eta):
mu_phi:=mu1[bf]*(a[mu1]+2*b[mu1]*phi(eta)):
gama1:=0.00:
a[mu1]:=39.11:
b[mu1]:=533.9:
mu1[bf]:=9.93/10000:
a[k1]:=7.47:
b[k1]:=0:
k1[bf]:=0.597:
zet:=1:
phi1[w]:=phi0:
mu1[w]:=mu(0):
k1[w]:=k(0):

eq1:=subs(phi(0)=phi0,eq1);
eq2:=subs(phi(0)=phi0,eq2);
eq3:=subs(phi(0)=phi0,eq3);
/  d   /  d         \\   //                                    
|----- |----- u(eta)|| + \\0.0009930000000 + 0.03883623000 phi0
\ deta \ deta       //                                         

                      2\                                 
   + 0.5301627000 phi0 / (sigma - 500 phi(eta) + 500 phi0

                           \//               
   - (1 - phi(eta)) T(eta))/ \0.0009930000000

                                                   2\   
   + 0.03883623000 phi(eta) + 0.5301627000 phi(eta) / +

  /                                       /  d           \ /  d  
  |(0.03883623000 + 1.060325400 phi(eta)) |----- phi(eta)| |-----
  \                                       \ deta         / \ deta

         \\//                                        
   u(eta)|| \0.0009930000000 + 0.03883623000 phi(eta)
         //                                          

                          2\
   + 0.5301627000 phi(eta) /
           /  d         \     0.597 + 4.45959 phi0  
           |----- T(eta)| - ------------------------
           \ deta       /   0.597 + 4.45959 phi(eta)
                                        /  d         \
                            1. phi(eta) |----- T(eta)|
         /  d           \               \ deta       /
         |----- phi(eta)| - --------------------------
         \ deta         /                           2
                             0.5 cc + 0.75 - 0.75 cc  
Q:=proc(pp2,fi0) option remember; local res,F0,F1,F2,a,INT0,INT10,B;
print(pp2,fi0);
if not type([pp2,fi0],list(numeric)) then return 'procname(_passed)' end if;
res := dsolve(subs(sigma=pp2,phi0=fi0,{eq1=0,eq2=0,eq3=0,u(1)=-lambda*D(u)(1),u(0)=lambda*D(u)(0),phi(0)=phi0,T(0)=0}), numeric,output=listprocedure,initmesh=10, continuation=cc);
F0,F1,F2:=op(subs(res,[u(eta),phi(eta),T(eta)]));
INT0:=evalf(Int((abs(F0(eta)),eta=0..1)));
INT10:=evalf(Int(abs(F0(eta))*F1(eta),eta=0..1));
a[1]:=evalf(Int(F0(eta)*(F1(eta)*rhop+(1-F1(eta))*rhobf),eta=0..1));
#a[1]:=evalf(Int((F0(eta),eta=0..1)));
a[2]:=(INT10/INT0-Phiavg)/Phiavg; #relative
[a[1],a[2]]
end proc:
Q1:=proc(pp2,fi0) Q(_passed)[1] end proc;
Q2:=proc(pp2,fi0) Q(_passed)[2] end proc;
proc(pp2, fi0)  ...  end;
proc(pp2, fi0)  ...  end;
#Q(116,0.0041);
#tempe:=Optimization:-LSSolve([Q1,Q2],initialpoint=[130,0.01]);
#tempe:=Optimization:-LSSolve([Q1,Q2],initialpoint=[43.55,0.39]);
tempe:=Optimization:-LSSolve([Q1,Q2],initialpoint=[5.65,0.00036]);
#tempe:=Optimization:-LSSolve([Q1,Q2],initialpoint=[12,0.003]); # khoob ba 1
#tempe:=Optimization:-LSSolve([Q1,Q2],initialpoint=[5,0.01]);
                  HFloat(5.65), HFloat(3.6e-4)
           HFloat(5.650000070103341), HFloat(3.6e-4)
           HFloat(5.65), HFloat(3.600105456508193e-4)
     HFloat(29.63242379055208), HFloat(0.0205927592420527)
    HFloat(12.803902258015825), HFloat(0.006395385884750864)
    HFloat(12.803902403534572), HFloat(0.006395385884750864)
    HFloat(12.803902258015825), HFloat(0.00639539649402585)
   HFloat(12.804004931505949), HFloat(0.0063954867657199386)
    HFloat(12.804107604996073), HFloat(0.006395587646689013)
    HFloat(12.80400483062498), HFloat(0.006498160255844027)
    HFloat(12.803902157134855), HFloat(0.006498059374874952)
   HFloat(-1.0206939292143726), HFloat(-3.32764179807047e-4)
   HFloat(-1.0206939079125088), HFloat(-3.32764179807047e-4)
   HFloat(-1.0206939292143726), HFloat(-3.327536344433438e-4)
    HFloat(18.749500943683863), HFloat(0.01993840615828979)
    HFloat(3.9953780262640484), HFloat(0.00481041471606933)
     HFloat(6.166152606930136), HFloat(0.00703619658484674)
    HFloat(7.3193201827812295), HFloat(0.008218585352824569)
Error, (in Optimization:-LSSolve) complex value encountered
sigma:=tempe[2](1);
                          tempe[2](1)
phi0:=tempe[2](2);
                          tempe[2](2)
with(plots):

res2 := dsolve({eq1=0,eq2=0,eq3=0,u(1)=-lambda*D(u)(1),u(0)=lambda*D(u)(0),phi(0)=phi0,T(0)=0}, numeric,output=listprocedure,continuation=cc);
Error, (in dsolve/numeric/process_input) boundary conditions specified at too many points: {0, 1, 2}, can only solve two-point boundary value problems
G0,G1,G2:=op(subs(res2,[u(eta),phi(eta),T(eta)])):
ruu:=evalf((Int(abs(G0(eta))*(G1(eta)*rhop+(1-G1(eta))*rhobf ),eta=0..zet)))/(Phiavg*rhop+(1-Phiavg)*rhobf);
phb:=evalf((Int(abs(G0(eta))*G1(eta),eta=0..1))) / evalf((Int(abs(G0(eta)),eta=0..1))) ;
TTb:=evalf(Int(abs(G0(eta))*G2(eta)*(G1(eta)*rhop*cp+(1-G1(eta))*rhobf*cbf ),eta=0..1))/evalf(Int(abs(G0(eta))*(G1(eta)*rhop*cp+(1-G1(eta))*rhobf*cbf ),eta=0..1));
Error, invalid input: subs received res2, which is not valid for its 1st argument
                /  /1.                                        \
                | |                                           |
0.0008538922115 | |    |G0(eta)| (2881.8 G1(eta) + 998.2) deta|
                | |                                           |
                \/0.                                          /
                    /1.                       
                   |                          
                   |    |G0(eta)| G1(eta) deta
                   |                          
                  /0.                         
                  ----------------------------
                        /1.                   
                       |                      
                       |                      
                       |    |G0(eta)| deta    
                      /                       
                       0.                     
                                                              /Int(
                              1                               |     
------------------------------------------------------------- |     
  /1.                                                         |     
 |                                                            \     
 |              /             6                       6\            
 |    |G0(eta)| \-1.1752324 10  G1(eta) + 4.1744724 10 / deta       
/                                                                   
 0.                                                                 

                    /             6                       6\ , eta = 0. .. 1.)
  |G0(eta)| G2(eta) \-1.1752324 10  G1(eta) + 4.1744724 10 /                  

  \
  |
  |
  |
  /
#rhouu:=evalf((Int((G1(eta)*rhop+(1-G1(eta))*rhobf)*G0(eta),eta=0..1)));

odeplot(res2,[[eta,u(eta)/ruu],[eta,phi(eta)/phb],[eta,T(eta)/TTb]],0..1);
#odeplot(res2,[[eta,u(eta)],[eta,phi(eta)],[eta,T(eta)]],0..1);
Error, (in plots/odeplot) input is not a valid dsolve/numeric solution
rhou:=evalf((Int(abs(G0(eta))*(G1(eta)*rhop+(1-G1(eta))*rhobf ),eta=0..zet))):

Nub:=(1/G2(1))*(((1+a[k1]*abs(G1(0))+b[k1]*abs(G1(0))^2)/(1+a[k1]*Phiavg+b[k1]*Phiavg^2)));
                0.6905123602 (1 + 7.47 |G1(0)|)
                -------------------------------
                             G2(1)             
(rhs(res2(0.0000000000001)[3])-rhs(res2(0)[3]))/0.0000000000001;
Error, invalid input: rhs received res2(0.1e-12)[3], which is not valid for its 1st argument, expr
sigma;
                          tempe[2](1)
NBT;
                              0.5
>

 

the above code has been worked for NBT=0.6 and higher, whereas as NBT decreases, the code doesnt converge easily.

How can I fix this problem?

Thanks for your attention in advance

Amir

1 2 3 4 5 6 7 Last Page 1 of 11