## 20 Reputation

1 years, 105 days

## How can fix the error"Error, (in Optimiz...

Maple

Hello everyone. after runnig this maple code i get the error :" Error, (in Optimization:-NLPSolve) non-numeric result encountered" . How can fix it?

```restart;
Digits := 20;
with(LinearAlgebra);
with(linalg);
with(Optimization);
with(Student[Calculus1]);
NULL;
n := 2;
z := 1;
a := 0;
b := 1;
m := 2;
NULL;
PS1 := (j, t) -> piecewise(j = 0, 1, t^(j + s[j]));
PI1 := (j, t) -> piecewise(j = 0, 1, t^(j + q[j]));
PH1 := (j, t) -> piecewise(j = 0, 1, t^(j + h[j]));
PL1 := (j, t) -> piecewise(j = 0, 1, t^(j + l[j]));
NULL;
PS := t -> local j; Transpose(convert([seq(PS1(j, t), j = 0 .. n - 1)], Matrix));
P_I := t -> local j; Transpose(convert([seq(PI1(j, t), j = 0 .. n - 1)], Matrix));
PH := t -> local j; Transpose(convert([seq(PH1(j, t), j = 0 .. n - 1)], Matrix));
PL := t -> local j; Transpose(convert([seq(PL1(j, t), j = 0 .. n - 1)], Matrix));
Warning, (in PS) `j` is implicitly declared local
Warning, (in P_I) `j` is implicitly declared local
Warning, (in PH) `j` is implicitly declared local
Warning, (in PL) `j` is implicitly declared local

NULL;
NULL;
B1 := (i, j) -> piecewise(i = j and j = 1, 1, i = 1 and 1 < j, 0, i = j and j = 2, 1, i = 2 and 2 < j, 0, j <= i, (i + j - 2)!/(2^(j - 1)*(j - 1)!*(i - j)!));
NULL;

B := t -> Matrix(n, B1);

DS1 := (m, k) -> piecewise(m <= 1, 0, m = k, GAMMA(k + s[k - 1])/GAMMA(k + s[k - 1] - z));
DI1 := (m, k) -> piecewise(m <= 1, 0, m = k, GAMMA(k + i[k - 1])/GAMMA(k + i[k - 1] - z));
DH1 := (m, k) -> piecewise(m <= 1, 0, m = k, GAMMA(k + h[k - 1])/GAMMA(k + h[k - 1] - z));
DL1 := (m, k) -> piecewise(m <= 1, 0, m = k, GAMMA(k + l[k - 1])/GAMMA(k + l[k - 1] - z));
DS := t -> t^(-z)*Matrix(n, DS1);
DI := t -> t^(-z)*Matrix(n, DI1);
DH := t -> t^(-z)*Matrix(n, DH1);
DL := t -> t^(-z)*Matrix(n, DL1);
NULL;
NULL;

cs := i -> ps[i];
ci := j -> p[j];
ch := j -> ph[j];
cl := i -> pl[i];
CS := convert([seq(cs(i), i = 1 .. n)], Matrix);
CI := convert([seq(ci(i), i = 1 .. n)], Matrix);
CH := convert([seq(ch(i), i = 1 .. n)], Matrix);
CL := convert([seq(cl(i), i = 1 .. n)], Matrix);

NULL;
NULL;
NULL;
S := unapply(simplify(Multiply(Multiply(CS, B(t)), PS(t))[1, 1]), [t]);
I1 := unapply(simplify(Multiply(Multiply(CI, B(t)), P_I(t))[1, 1]), [t]);
H := unapply(simplify(Multiply(Multiply(CH, B(t)), PH(t))[1, 1]), [t]);
L := unapply(simplify(Multiply(Multiply(CL, B(t)), PL(t))[1, 1]), [t]);
DSS := unapply(simplify(Multiply(Multiply(Multiply(CS, B(t)), DS(t)), PS(t))[1, 1]), [t]);
DII := unapply(simplify(Multiply(Multiply(Multiply(CI, B(t)), DI(t)), P_I(t))[1, 1]), [t]);
DHH := unapply(simplify(Multiply(Multiply(Multiply(CH, B(t)), DH(t)), PH(t))[1, 1]), [t]);
DLL := unapply(simplify(Multiply(Multiply(Multiply(CL, B(t)), DL(t)), PL(t))[1, 1]), [t]);
NULL;

NULL;
RS := unapply(evalf(DSS(t) + (-0.0043217^z + 0.5944^z*Multiply(S(t), I1(t)) + (0.025^z + 0.0008^z)*S(t))), [t]);

RI := unapply(evalf(DII(t) + (-0.5944^z*Multiply(S(t), I1(t)) - 0.0056^z*Multiply(H(t), I1(t)) - 0.027^z*L(t) + (((0.025^z + 0.0008^z) + 0.025^z) + 0.5^z)*I1(t))), [t]);
RH := unapply(evalf(DHH(t) + (-0.535^z + 0.0056^z*Multiply(H(t), I1(t)) - 0.5^z*I1(t) + (0.025^z + 0.0008^z)*H(t))), [t]);
RL := unapply(evalf(DLL(t) + (-0.025^z*I1(t) + (0.025^z + 0.0008^z + 0.027^z)*L(t))), [t]);
R := unapply(evalf(RS(t)^2 + RI(t)^2 + RH(t)^2 + RL(t)^2), [t]);

NULL;

p1 := x -> (x^2 - 1)^m;
dmp1 := x -> diff(p1(x), x \$ m);
NULL;
p := x -> dmp1(x)/(2^m*m!);
eq := p(x) = 0;
r := solve(eq, x);
NULL;
ss := Vector[row](m);
w := Vector[row](m);
for i to m do
w[i] := 2/((-r[i]^2 + 1)*D(p)(r[i])^2);
ss[i] := w[i]*evalf(R((b - a)/2*r[i] + (b + a)/2));
end do;

Lambda := evalf((b - a)/2*SS);
;

C1 := S(0) - 43994 = 0;
C2 := I1(0) - 0.1 = 0;
C3 := H(0) = 0;
C4 := L(0) - 1 = 0;

NULL;
NLP := NLPSolve(Lambda, {C1, C2, C3, C4});
Error, (in Optimization:-NLPSolve) non-numeric result encountered
```

## Could not store error...

Maple
```restart;
with(Optimization);
with(Student[Calculus1]);
z1 := 0.15;
z1 := 0.15

z2 := 0.85;
z2 := 0.85

NULL;
Q := Matrix(3, 3, [1, 0, 0, 1, 1, 0, 1, 3, 3]);
P_S := Matrix(1, 3, [ps0, ps1, ps2]);
Phi_S := Matrix(3, 1, [1, t^(1 + gs1), t^(2 + gs2)]);
dz1Phi_S := t^z1*Matrix(3, 3, [0, 0, 0, 0, Gamma(gs1 + 2)/Gamma(gs1 + 2 - z1), 0, 0, 0, Gamma(gs2 + 3)/Gamma(gs2 + 3 - z1)]);
dz2Phi_S := t^z2*Matrix(3, 3, [0, 0, 0, 0, Gamma(gs1 + 2)/Gamma(gs1 + 2 - z2), 0, 0, 0, Gamma(gs2 + 3)/Gamma(gs2 + 3 - z2)]);
NULL;
P_I := Matrix(1, 3, [p_i0, p_i1, p_i2]);
Phi_I := Matrix(3, 1, [1, t^(1 + gi1), t^(2 + gi2)]);
NULL;
dz1Phi_I := t^z1*Matrix(3, 3, [0, 0, 0, 0, Gamma(gi1 + 2)/Gamma(gi1 + 2 - z1), 0, 0, 0, Gamma(gi2 + 3)/Gamma(gi2 + 3 - z1)]);
dz2Phi_I := t^z2*Matrix(3, 3, [0, 0, 0, 0, Gamma(gi1 + 2)/Gamma(gi1 + 2 - z2), 0, 0, 0, Gamma(gi2 + 3)/Gamma(gi2 + 3 - z2)]);
P_H := Matrix(1, 3, [ph0, ph1, ph2]);
Phi_H := Matrix(3, 1, [1, t^(1 + gh1), t^(2 + gh2)]);
dz1Phi_H := t^z1*Matrix(3, 3, [0, 0, 0, 0, Gamma(gh1 + 2)/Gamma(gh1 + 2 - z1), 0, 0, 0, Gamma(gh2 + 3)/Gamma(gh2 + 3 - z1)]);
dz2Phi_H := t^z1*Matrix(3, 3, [0, 0, 0, 0, Gamma(gh1 + 2)/Gamma(gh1 + 2 - z2), 0, 0, 0, Gamma(gh2 + 3)/Gamma(gh2 + 3 - z2)]);
P_L := Matrix(1, 3, [pl0, pl1, pl2]);
Phi_L := Matrix(3, 1, [1, t^(1 + gl1), t^(2 + gl2)]);
dz1Phi_L := t^z1*Matrix(3, 3, [0, 0, 0, 0, Gamma(gl1 + 2)/Gamma(gl1 + 2 - z1), 0, 0, 0, Gamma(gl2 + 3)/Gamma(gl2 + 3 - z1)]);
dz2Phi_L := t^z1*Matrix(3, 3, [0, 0, 0, 0, Gamma(gl1 + 2)/Gamma(gl1 + 2 - z2), 0, 0, 0, Gamma(gl2 + 3)/Gamma(gl2 + 3 - z2)]);
S := (P_S . Q) . Phi_S;
NULL;
ds1 := simplify(((P_S . Q) . dz1Phi_S) . Phi_S, GAMMA);
ds2 := simplify(((P_S . Q) . dz2Phi_S) . Phi_S);
H := (P_H . Q) . Phi_H;
NULL;
NULL;
dh1 := simplify(((P_H . Q) . dz1Phi_H) . Phi_H, GAMMA);
dh2 := simplify(((P_H . Q) . dz2Phi_H) . Phi_H);
NULL;
L := (P_L . Q) . Phi_L;
NULL;
dl1 := simplify(((P_L . Q) . dz1Phi_L) . Phi_L, GAMMA);
dl2 := simplify(((P_L . Q) . dz2Phi_L) . Phi_L);
NULL;
I3 := (P_I . Q) . Phi_I;
di1 := simplify(((P_I . Q) . dz1Phi_I) . Phi_I, GAMMA);
di2 := simplify(((P_I . Q) . dz2Phi_I) . Phi_I);
RS1 := ds1 + (-0.0043217^z1 + ((0.125^z1*S) . I3) + (0.002^z1 + 0.0008^z1)*S);
RS2 := ds2 + (-0.0043217^z2 + ((0.125^z2*S) . I3) + (0.002^z2 + 0.0008^z2)*S);
RH1 := dh1 + (-0.535^z1 + ((0.0056^z1*H) . I3) - 0.35^z1 + (0.002^z1 + 0.0008^z1)*H);
RH2 := dh2 + (-0.535^z2 + ((0.0056^z2*H) . I3) - 0.35^z2 + (0.002^z2 + 0.0008^z2)*H);
RI1 := di1 + (-((0.125^z1*S) . I3) - ((0.0056^z1*H) . I3) - 0.029^z1*L + (0.002^z1 + 0.0008^z1 + 0.025^z1 + 0.35^z1)*I3);
RI2 := di2 + (-((0.125^z2*S) . I3) - ((0.0056^z2*H) . I3) - 0.029^z2*L + (0.002^z2 + 0.0008^z2 + 0.025^z2 + 0.35^z2)*I3);
RL1 := dl1 + (-0.025^z1*I3 + (0.002^z1 + 0.0008^z1 + 0.029^z1)*L);
RL2 := dl2 + (-0.025^z2*I3 + (0.002^z2 + 0.0008^z2 + 0.029^z2)*L);
R15 := evalf(RH1^2 + RI1^2 + RL1^2 + RS1^2, 4);

I1 := evalf(ApproximateInt(R15[1, 1], t = 0 .. 1), 4);
NULL;
h := 0.01;
B := zeros([1, 20]);
A := Matrix(1, 20, [ps0, ps1, ps2, p_i0, p_i1, p_i2, ph0, ph1, ph2, pl0, pl1, pl2, gs1, gs2, gi1, gi2, gh1, gh2, gl1, gl2]);
NULL;
for i to 20 do
B[1, i] := evalf(diff(I1, A[1, i]), 4);
end do;
NULL;
NLPSolve(I1, {B[1, 1] = 0, B[1, 2] = 0, B[1, 3] = 0, B[1, 4] = 0, B[1, 5] = 0, B[1, 6] = 0, B[1, 7] = 0, B[1, 8] = 0, B[1, 9] = 0, B[1, 10] = 0, B[1, 11] = 0, B[1, 12] = 0, B[1, 13] = 0, B[1, 14] = 0, B[1, 15] = 0, B[1, 16] = 0, B[1, 17] = 0, B[1, 18] = 0, B[1, 19] = 0, B[1, 20] = 0});
Error, (in Optimization:-NLPSolve) could not store .2000*(4.61629127484374902+.6380*(.100000000000000019e-1*Gamma(3.)*Gamma(3.85)+.375000000000000116e-3*Gamma(4.)*Gamma(2.85))/Gamma(2.85)/Gamma(3.85))*(.6380*(.100000000000000019e-1*Gamma(3.)*D(Gamma)(3.85)+.375000000000000116e-3*D(Gamma)(4.)*Gamma(2.85)-.112350000000000015e-2*Gamma(4.)*Gamma(2.85))/Gamma(2.85)/Gamma(3.85)-.6380*(.100000000000000019e-1*Gamma(3.)*Gamma(3.85)+.375000000000000116e-3*Gamma(4.)*Gamma(2.85))/Gamma(2.85)/Gamma(3.85)^2*D(Gamma)(3.85)-.238097850000000034e-2)+.594623719800000056e-3*(.333300000000000046e-2*Gamma(3.)*Gamma(3.85)+.125000000000000030e-3*Gamma(4.)*Gamma(2.8...

```

Hello everybody. after running this code in Maple i get NLPSolve error (could not store...). I asked this question before and shared a picture. now i well share the code. how can i fix this error?

 Page 1 of 1
﻿