Items tagged with optimization optimization Tagged Items Feed

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

> sol := pdsolve({ICS, sys1, sys2, sys3, sys4, sys5, sys6, sys7}, numeric, method = rkf45, parameters = [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p], output = listprocedure);

Error, (in pdsolve) invalid input: `pdsolve/numeric` expects its 2nd argument, IBCs, to be of type {set, list}, but received method = rkf45

 

restart;

x11:=[1.05657970467127, .369307407127487, .400969917393968, .368036162749865, .280389875142339, .280523489139136, .283220960827744, .373941285224253, .378034013792196, .384412762008662, .358678988563716, .350625923673556, .852039817522304, .362240519978640, 1.03197080591829, .343650441408896, .982510654490390, .404544012440991, .422063867224247, 1.20938803285209, .455708586000668, 1.22503869712995, .388259397947667, .472188904769827, 1.31108028794286, 1.19746589728366, .572669348193002];

y11:= [.813920951682113, 10.3546712426210, 2.54581301217449, 10.2617298458172, 3.82022939508992, 3.81119683373741, 3.90918914917183, 10.5831132713329, 10.8700088489538, 11.0218056177585, 10.5857571473115, 9.89034057997145, .271497107157453, 9.77706473740146, 2.23955104698355, 4.16872072216206, .806710906391666, 11.9148193656260, 12.0521411908477, 2.52812993540440, 12.6348841508094, 2.72197067934160, 5.10891266728297, 13.3609183272238, 3.03572692234234, 1.07326033849793, 15.4268962507711];

z11:= [8.93290500985527, 8.96632856524217, 15.8861149154785, 9.16576669760908, 3.20341865536950, 3.11740291181539, 3.22328961317946, 8.71094047480794, 8.60596466961827, 9.15440788281943, 10.2935566768586, 10.5765776143026, 16.3469510439066, 9.36885507010739, 2.20434678689869, 3.88816077008078, 17.9816287534802, 10.1414228793737, 10.7356141216242, 4.00703203725441, 12.0105837616461, 3.77028605914906, 5.01411979976607, 12.7529165152417, 3.66800269682059, 21.2178824031985, 13.9148746721034];

u11 := [5.19, 5.37, 5.56, 5.46, 5.21, 5.55, 5.56, 5.61, 5.91, 5.93, 5.98, 6.28, 6.24, 6.44, 6.58, 6.75, 6.78, 6.81, 7.59, 7.73, 7.75, 7.69, 7.73, 7.79, 7.91, 7.96, 8.05];

u11 := [seq(close3(t+t3), t3=0..26)];

sys1:=Diff(a1(s,t),s) = a*a1(s,t)+ b*a2(s,t)+ c*a3(s,t)+ d*u(t);

sys2:=Diff(a2(s,t),s) = e*a1(s,t)+ f*a2(s,t)+ g*a3(s,t)+ h*u(t);

sys3:=Diff(a3(s,t),s) = i*a1(s,t)+ j*a2(s,t)+ k*a3(s,t)+ l*u(t);

sys4:=Diff(y(t),t) = m*a1(s,t)+n*a2(s,t)+ o*a3(s,t)+ p*u(t);

sys5:= Diff(a1(s,t),t) = a1(s,t);

sys6:= Diff(a2(s,t),t) = a2(s,t);

sys7:= Diff(a3(s,t),t) = a3(s,t);

sol := pdsolve([sys1, sys2, sys3,sys4,sys5,sys6,sys7]);

t2 := [seq(i, i=1..27)];

xt1 := subs(_C1=1,sol[1]); # a1(t)

xt2 := subs(_C1=1,sol[2]); # a2(t)

xt3 := subs(_C1=1,sol[3]); # a3(t)

ut1 := subs(_C1=1,sol[4]); # u(t)

tim := [seq(n, n=1..27)];

N:=nops(tim):

ICS:=a1(1)=x11[1],a2(1)=y11[1],a3(1)=z11[1],u1(1)=u11[1];

sol:=pdsolve({sys1, sys2, sys3,sys4,sys5,sys6,sys7,ICS}, numeric, method=rkf45, parameters=[ a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p],output=listprocedure);

ans(.001,.002,.003,.001,.002,.003,.001,.002,.003,.003,.003,.003,.003,.003,.003,.003);

ans:=proc(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) sol(parameters=[ a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p]);

add((xt1(tim[i])-x11[i])^2,i=1..N)+add((xt2(tim[i])-y11[i])^2,i=1..N)+add((xt3(tim[i])-z11[i])^2,i=1..N)+add((ut1(tim[i])-u11[i])^2,i=1..N);

end proc;

result1 := Optimization:-Minimize(ans,initialpoint=[.001,.002,.003,.001,.002,.003,.001,.002,.003,.003,.003,.003,.003,.003,.003,.003]);

Hi,

I get the error in the following code

restart:

gama1:=0.01:

zet:=0;
#phi0:=0.00789:
Phiavg:=0.02;
lambda:=0.01;
Ha:=1;


                               0
                              0.02
                              0.01
                               1
rhocu:=2/(1-zet^2)*int((1-eta)*rho(eta)*c(eta)*u(eta),eta=0..1-zet):

eq1:=diff(u(eta),eta,eta)+1/(mu(eta)/mu1[w])*(1-Ha^2*u(eta))+((1/(eta)+1/mu(eta)*(mu_phi*diff(phi(eta),eta)))*diff(u(eta),eta));
eq2:=diff(T(eta),eta,eta)+1/(k(eta)/k1[w])*(-2/(1-zet^2)*rho(eta)*c(eta)*u(eta)/(p2*10000)+( (a[k1]+2*b[k1]*phi(eta))/(1+a[k1]*phi1[w]+b[k1]*phi1[w]^2)*diff(phi(eta),eta)+k(eta)/k1[w]/(eta)*diff(T(eta),eta) ));
eq3:=diff(phi(eta),eta)+phi(eta)/(N[bt]*(1+gama1*T(eta))^2)*diff(T(eta),eta);
      /  d   /  d         \\   mu1[w] (1 - u(eta))
      |----- |----- u(eta)|| + -------------------
      \ deta \ deta       //         mu(eta)      

           /             /  d           \\               
           |      mu_phi |----- phi(eta)||               
           | 1           \ deta         /| /  d         \
         + |--- + -----------------------| |----- u(eta)|
           \eta           mu(eta)        / \ deta       /
                                /      /                        
                                |      |                        
/  d   /  d         \\     1    |      |  rho(eta) c(eta) u(eta)
|----- |----- T(eta)|| + ------ |k1[w] |- ----------------------
\ deta \ deta       //   k(eta) |      |         5000 p2        
                                \      \                        

                                /  d           \
     (a[k1] + 2 b[k1] phi(eta)) |----- phi(eta)|
                                \ deta         /
   + -------------------------------------------
                                          2     
         1 + a[k1] phi1[w] + b[k1] phi1[w]      

            /  d         \\\
     k(eta) |----- T(eta)|||
            \ deta       /||
   + ---------------------||
           k1[w] eta      ||
                          //
                                      /  d         \
                             phi(eta) |----- T(eta)|
          /  d           \            \ deta       /
          |----- phi(eta)| + ------------------------
          \ deta         /                          2
                             N[bt] (1 + 0.01 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)):

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:=0.5:
#phi(0):=1:
#u(0):=0:
phi1[w]:=phi0:
N[bt]:=0.2:
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):

#A somewhat speedier version uses the fact that you really need only compute 2 integrals not 3, since one of the integrals can be written as a linear combination of the other 2:
Q:=proc(pp2,fi0) local res,F0,F1,F2,a,INT0,INT10,B;
global Q1,Q2;
print(pp2,fi0);
if not type([pp2,fi0],list(numeric)) then return 'procname(_passed)' end if:
res := dsolve(subs(p2=pp2,phi0=fi0,{eq1=0,eq2=0,eq3=0,u(1)=lambda/(phi(1)*rhop/rhobf+(1-phi(1)))*D(u)(1),D(u)(0)=0,phi(1)=phi0,T(1)=0,D(T)(1)=1}), numeric,output=listprocedure):
F0,F1,F2:=op(subs(res,[u(eta),phi(eta),T(eta)])):
INT0:=evalf(Int((1-eta)*F0(eta),eta=0..1-zet));
INT10:=evalf(Int((1-eta)*F0(eta)*F1(eta),eta=0..1-zet));
B:=(-cbf*rhobf+cp*rhop)*INT10+ rhobf*cbf*INT0;
a[1]:=2/(1-zet^2)*B-10000*pp2;
a[2]:=INT10/INT0-Phiavg;
Q1(_passed):=a[1];
Q2(_passed):=a[2];
if type(procname,indexed) then a[op(procname)] else a[1],a[2] end if
end proc;
#The result agrees very well with the fsolve result.
#Now I did use a better initial point. But if I start with the same as in fsolve I get the same result in just about 2 minutes, i.e. more than 20 times as fast as fsolve:

Q1:=proc(pp2,fi0) Q[1](_passed) end proc;
Q2:=proc(pp2,fi0) Q[2](_passed) end proc;
Optimization:-LSSolve([Q1,Q2],initialpoint=[6.5,exp(-1/N[bt])]);


proc(pp2, fi0)  ...  end;
proc(pp2, fi0)  ...  end;
proc(pp2, fi0)  ...  end;
              HFloat(6.5), HFloat(0.006737946999)

 

 

the error is :

Error, (in Optimization:-LSSolve) system is singular at left endpoint, use midpoint method instead

how can I fix it.

Thanks

 

Amir

How to set feasibility tolerance for optimization command?

Any example to show some syntax.

got error when draw root locus

and would like to know how to set feasibility tolerance, less than 0.1 is also ok

 

with(DynamicSystems):

x11 := [1.05657970467127, .369307407127487, .400969917393968, .368036162749865, .280389875142339, .280523489139136, .283220960827744, .373941285224253, .378034013792196, .384412762008662, .358678988563716, .350625923673556, .852039817522304, .362240519978640, 1.03197080591829, .343650441408896, .982510654490390, .404544012440991, .422063867224247, 1.20938803285209, .455708586000668, 1.22503869712995, .388259397947667, .472188904769827, 1.31108028794286, 1.19746589728366, .572669348193002];

y11 := [.813920951682113, 10.3546712426210, 2.54581301217449, 10.2617298458172, 3.82022939508992, 3.81119683373741, 3.90918914917183, 10.5831132713329, 10.8700088489538, 11.0218056177585, 10.5857571473115, 9.89034057997145, .271497107157453, 9.77706473740146, 2.23955104698355, 4.16872072216206, .806710906391666, 11.9148193656260, 12.0521411908477, 2.52812993540440, 12.6348841508094, 2.72197067934160, 5.10891266728297, 13.3609183272238, 3.03572692234234, 1.07326033849793, 15.4268962507711];

z11 := [8.93290500985527, 8.96632856524217, 15.8861149154785, 9.16576669760908, 3.20341865536950, 3.11740291181539, 3.22328961317946, 8.71094047480794, 8.60596466961827, 9.15440788281943, 10.2935566768586, 10.5765776143026, 16.3469510439066, 9.36885507010739, 2.20434678689869, 3.88816077008078, 17.9816287534802, 10.1414228793737, 10.7356141216242, 4.00703203725441, 12.0105837616461, 3.77028605914906, 5.01411979976607, 12.7529165152417, 3.66800269682059, 21.2178824031985, 13.9148746721034];

u11 := [5.59, 5.74, 5.49, 5.19, 5.37, 5.56, 5.46, 5.21, 5.55, 5.56, 5.61, 5.91, 5.93, 5.98, 6.28, 6.24, 6.44, 6.58, 6.75, 6.78, 6.81, 7.59, 7.73, 7.75, 7.69, 7.73, 7.79];

a1 := Diff(x1(t),t) = k1*x1(t)+ k2*y1(t)+ k3*z1(t)+k4*u1(t);

b1 := Diff(y1(t),t) = k5*x1(t)+ k6*y1(t)+ k7*z1(t)+k8*u1(t);

c1 := Diff(z1(t),t) = k8*x1(t)+ k9*y1(t)+ k10*z1(t)+k12*u1(t);

d1 := Diff(u1(t),t) = 0;

ICS:=x1(1)=x11[1],y1(1)=y11[1],z1(1)=z11[1],u1(1)=u11[27];

sol:=dsolve({a1,b1,c1,d1,ICS}, numeric, method=rkf45, parameters=[k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12],output=listprocedure);

X,Y,Z,U:=op(subs(sol,[x1(t),y1(t),z1(t),u1(t)]));

tim := [seq(n, n=1..27)];

N:=nops(tim):

ans:=proc(k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12) sol(parameters=[k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12]);

 add((X(tim[i])-x11[i])^2,i=1..N)+add((Y(tim[i])-y11[i])^2,i=1..N)+add((Z(tim[i])-z11[i])^2,i=1..N)+add((U(tim[i])-u11[i])^2,i=1..N)

 end proc;

ans(.001,.002,.003,.001,.002,.003,.001,.002,.003,.001,.002,.003);

result1 := Optimization:-Minimize(ans,initialpoint=[.001,.002,.003,.001,.002,.003,.001,.002,.003,.001,.002,.003]);

x11 := [1.05657970467127, .369307407127487, .400969917393968, .368036162749865, .280389875142339, .280523489139136, .283220960827744, .373941285224253, .378034013792196, .384412762008662, .358678988563716, .350625923673556, .852039817522304, .362240519978640, 1.03197080591829, .343650441408896, .982510654490390, .404544012440991, .422063867224247, 1.20938803285209, .455708586000668, 1.22503869712995, .388259397947667, .472188904769827, 1.31108028794286, 1.19746589728366, .572669348193002];

y11 := [.813920951682113, 10.3546712426210, 2.54581301217449, 10.2617298458172, 3.82022939508992, 3.81119683373741, 3.90918914917183, 10.5831132713329, 10.8700088489538, 11.0218056177585, 10.5857571473115, 9.89034057997145, .271497107157453, 9.77706473740146, 2.23955104698355, 4.16872072216206, .806710906391666, 11.9148193656260, 12.0521411908477, 2.52812993540440, 12.6348841508094, 2.72197067934160, 5.10891266728297, 13.3609183272238, 3.03572692234234, 1.07326033849793, 15.4268962507711];

z11 := [8.93290500985527, 8.96632856524217, 15.8861149154785, 9.16576669760908, 3.20341865536950, 3.11740291181539, 3.22328961317946, 8.71094047480794, 8.60596466961827, 9.15440788281943, 10.2935566768586, 10.5765776143026, 16.3469510439066, 9.36885507010739, 2.20434678689869, 3.88816077008078, 17.9816287534802, 10.1414228793737, 10.7356141216242, 4.00703203725441, 12.0105837616461, 3.77028605914906, 5.01411979976607, 12.7529165152417, 3.66800269682059, 21.2178824031985, 13.9148746721034];

u11 := [5.59, 5.74, 5.49, 5.19, 5.37, 5.56, 5.46, 5.21, 5.55, 5.56, 5.61, 5.91, 5.93, 5.98, 6.28, 6.24, 6.44, 6.58, 6.75, 6.78, 6.81, 7.59, 7.73, 7.75, 7.69, 7.73, 7.79];

k1 := result1[2][1];

k2 := result1[2][2];

k3 := result1[2][3];

k4 := result1[2][4];

k5 := result1[2][5];

k6 := result1[2][6];

k7 := result1[2][7];

k8 := result1[2][8];

k9 := result1[2][9];

k10 := result1[2][10];

k11 := result1[2][11];

k12 := result1[2][12];

a1 := Diff(x1(t),t) = k1*x1(t)+ k2*y1(t)+ k3*z1(t)+k4*u1(t);

b1 := Diff(y1(t),t) = k5*x1(t)+ k6*y1(t)+ k7*z1(t)+k8*u1(t);

c1 := Diff(z1(t),t) = k8*x1(t)+ k9*y1(t)+ k10*z1(t)+k12*u1(t);

d1 := Diff(u1(t),t) = 0;

diff_eq := [a1, b1, c1, d1];

sys6 := DiffEquation(diff_eq, [x1(t), y1(t), z1(t), u1(t)], [x1(t), y1(t), z1(t), u1(t)]);

sys6 := DiffEquation(diff_eq, [x1(t), y1(t), z1(t)], [x1(t), y1(t), z1(t), u1(t)]);

ResponsePlot(sys6, Step(), parameters = params);

RootLocusPlot(sys6);

 

> sys6 := DiffEquation(diff_eq, [], [x1(t), y1(t), z1(t), u1(t)]);

Error, (in DynamicSystems:-DiffEquation) unrecognized diff-equation type: 9

> sys6 := DiffEquation(diff_eq, [x1(t), y1(t), z1(t), u1(t)], [x1(t), y1(t), z1(t), u1(t)]); sys6 := DiffEquation(diff_eq, [x1(t), y1(t), z1(t)], [x1(t), y1(t), z1(t), u1(t)]);

Error, (in DynamicSystems:-DiffEquation) unrecognized diff-equation type: 9

Error, (in DynamicSystems:-DiffEquation) unrecognized diff-equation type: 9

> ResponsePlot(sys6, Step(), parameters = params); RootLocusPlot(sys6);

Error, invalid input: DynamicSystems:-ResponsePlot expects value for keyword parameter parameters to be of type ({set, list})(name = complexcons), but received params

Error, (in Verify:-CommonExports) system object is not a module

 

Minimize doesn't work with dsolve porcedure?

experiment_real.mw

tr := proc (x, y)::integer; tr := x+y; result := x^(2+y) end proc

Warning, `result` is implicitly declared local to procedure `tr`

 

tr(5, 5)

78125

(1)

with(Optimization); Minimize(tr(x, y), x = 0 .. 1000, y = 1 .. 1, initialpoint = {x = 25, y = 1})

[0.117556065072605623e-15, [x = HFloat(4.898709434833346e-6), y = HFloat(1.0)]]

(2)

xxx := 97.39391293; yyy := -1.588898710

-1.588898710

(3)

xx := 100;

3

(4)

trool := proc (leng, alpha)::integer; global psi, zx, zy, xx, yy, xxx, yyy, sa, ca, ps, Vx, Vy, vx, vy, ode, ics, XX, YY, trool, G, str, start, ds; sa := evalf(sin(alpha)); ca := evalf(cos(alpha)); ps := evalf(evalc(Im(evalc(str*(x+I*y)-((1/2)*I)*G*ln(x+I*y-start)/Pi)))); psi := ps; xxx := evalf(xx+leng*ca); yyy := evalf(yy+leng*sa); Vx := diff(psi, y); Vy := -(diff(psi, x)); vx := Re(evalf(subs(x = xxx, y = yyy, subs(vvx = Vx, vvx)))); vy := Re(evalf(subs(x = xxx, y = yyy, subs(vvy = Vy, vvy)))); proc (X) options operator, arrow; X(t) end proc; proc (Y) options operator, arrow; Y(t) end proc; zx := proc (t) options operator, arrow; evalf(subs(x = X(t), y = Y(t), subs(vvx = Vx, vvx))) end proc; zy := proc (t) options operator, arrow; evalf(subs(x = X(t), y = Y(t), subs(vvy = Vy, vvy))) end proc; ode := diff(X(t), t) = zx(t), diff(Y(t), t) = zy(t); ics := X(0) = xxx, Y(0) = yyy; ds := dsolve([ode, ics], type = numeric, [X(t), Y(t)], method = rkf45, maxfun = 0, output = listprocedure, abserr = 0.1e-3, relerr = 0.1e-3, minstep = 0.1e-1); XX := rhs(ds[2]); YY := rhs(ds[3]); trool := XX(0.1e-3) end proc:

with(Optimization); Minimize(trool(alpha, leng), assume = nonnegative, alpha = 0 .. 2*Pi, leng = .2 .. 2, iterationlimit = 1000, initialpoint = {alpha = 1, leng = 1})

Error, (in XX) parameter 'alpha' must be assigned a numeric value before obtaining a solution

 

alpha = 0 .. 2*Pi, leng = .2 .. 2, output = solutionmodule

alpha := 1; leng := 1; XX(10)

HFloat(100.54666738117751)

(5)

``

trool(1, 11)

HFloat(100.00711298362239)

(6)

psi

3.*y-11.93662073*ln((x-100.)^2+y^2)

(7)

``

 

Download experiment_real.mw

with trool procedure minimize dosent work .... and its make me realy sad, couse i need to optimize alpha and leng in other (big one) porcedure with same dsolve.

get this errors:
"Warning, The use of global variables in numerical ODE problems is deprecated, and will be removed in a future release. Use the 'parameters' argument instead (see ?dsolve,numeric,parameters)"
"Error, (in XX) parameter 'alpha' must be assigned a numeric value before obtaining a solution"

Let a convex polygon, for example Q:=polygon([[0,2],[1,4],[4,4],[5,1],[3,0]]), be given.
How to find the disk of the biggest radius which is contained in Q?
How to find the disk of the smallest radius which contains Q? Of course, with Maple.

Let a convex polygon, for example Q:=polygon([[0,2],[1,4],[4,4],[5,1],[3,0]]), be given.
How to find the rectangle of the biggest area which is contained in Q?
A procedure is required. This problem seems to be more complex than the previous one.

Let the polygon P:=polygon([[0,2],[1,4],[2,3.5],[4,4],[5,1],[4,0.75],[3,0]])

be given.
How to find the rectangle of the minimal area which contains P? Of course, with Maple. Is it a rectangle having a side parallel to the longest diagonal of P?
The same problem in the general case: a procedure is required.

I have a set of around 60 linear equations with symbolic coefficients. ie

 

a*x1 + b*x2 + ... + c*x60 = 1

x1 + (c-a)*x2 + ... + d*x60 = 0

...

c*x1 + d*x2 + ... + b*x60 = a

 

The coefficients a,b,c,d are functions of x1...x60. I am trying to find the values of these coefficients. When I had a smaller set of equations I was solving them symbolically to find x1...x60 in terms of a,b,c,d and then using this solution to solve for a,b,c,d. I can no longer solve the set of equations symbolically as it is too large. How do I find the coefficients? I had some sort of optimization routine in mind.

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