petrivka

45 Reputation

4 Badges

12 years, 326 days

MaplePrimes Activity


These are answers submitted by petrivka

Sorry, I should have stated where t shows up--it is in the parameter "xinot," as the simple expression v*t/L (v and L are known values).

I'm running this in Maple 12 on a Pentium 4 (old, I know), and I'm getting in the range of 25 seconds with this one operation. I tried removing the dependence on t from the expression and execute the code as just numeric values, and it still takes about 20 seconds. I guess there isn't much I can do then to improve the runtime short of getting a new computer?

Could it be that accessing the terms of lam, beta, and all those others is slowing things down? I have those defined in a similar manner as the coefficient c, i.e.:

for i from 1 to 128 do

lam[i]:=somerootofaperiodicfunction

end:

-sidenote: I'm not sure really what kind of datatype I'm creating with this sort of definition, since it's not a list or an array. Maybe a table? Maple datatypes are kind of confusing to me, honestly.

Thanks for your help thus far.

Thank you both for your help so far. That was a good call, pagan, on the unnecessary computations I was introducing. It looks like I'm getting closer to actually solving for the variables Kguess[1] and Kguess[2], but I'm running into this new issue, as follows:

> errorfunc := Vector(nn); for i to nn do errorfunc[i] := evalf((Nodes[i]-ROM[i])/Nodes[i]) end do;
> ObjectiveFunction := add(errorfunc[i], i = 1 .. nn)/nn;
> Optimization:-NLPSolve(ObjectiveFunction, {ObjectiveFunction >= -.20, ObjectiveFunction <= .20});

Error, (in Optimization:-NLPSolve) no improved point could be found

Now, I know what the values of Kguess[1] and Kguess[2] should be, and when I input these values manually into the vector f and execute the ObjectiveFunction, I get a value of 0.15, which should satisfy the constraints that I had added to NLPSolve.

Also, I tried adding in bounds for Kguess[1] and Kguess[2] with the following code:

> bl := <A[1], Pe[1]>;
> bu := <A[na], Pe[nPe]>;
> Optimization:-NLPSolve(ObjectiveFunction, [ObjectiveFunction <= .20, ObjectiveFunction >= -.20], [bl, bu]);
Error, (in Optimization:-NLPSolve) unexpected parameters: [Vector(2, {(1) = 1/5, (2) = 3000}), Vector(2, {(1) = 2, (2) = 30000})]

Thank you for your patience and assistance!

Acer,

You're right about the procedure problem. I was trying to follow the examples in the help files as closely as I could, and that led to doing things in a more complicated way than necessary. So, I tried to put the objective function directly into NLPSolve as you suggested, along with the constraint that the objective function should not exceed 0.05, and this is the result:

> Optimization:-NLPSolve(add(ObjectiveFunction[i], i = 1 .. nn)/nn, add(ObjectiveFunction[i], i = 1 .. nn)/nn <= 0.5e-1, assume = nonnegative);
Error, (in Optimization:-NLPSolve) unexpected parameters: Lots of stuff containing Kguess[1] and Kguess[2]

I can't seem to convince NLPSolve that Kguess[1] and Kguess[2] are the parameters to be expected, and that they are the variables to be changed to meet the constraint I specified. I even tried constructing the matrix ROM within NLPSolve from Phi, C, and f, and I get the same result, except with a much longer computation time before the error.

Sorry if this problem seems elementary, but I do appreciate your help in resolving this issue.

Sorry, I probably should have just posted this in the beginning.

> restart;

> with(plots);

> with(LinearAlgebra);

> with(ArrayTools);

# These data are from earlier calculations which are rather time consuming

> A := ImportVector(ROMA); Pe := ImportVector(ROMPe); B := ImportMatrix(ROMB); Phi := ImportMatrix(ROMPhi); beta := ImportVector(ROMBeta); N := ImportVector(ROMN); Y := ImportVector(ROMY); ypos := ImportVector(ROMypos); timestep := ImportVector(ROMtimestep);

> na := Size(A, 1); n := Size(Phi, 2); nn := Size(Phi, 1); nPe := Size(Pe, 1); nypos := Size(ypos, 1); ntimestep := Size(timestep, 1);

# K contains parameter values on which the reduced order model is based

> K := Matrix(1 .. n, 1 .. 1); ii := 1; for i to na do for j to nPe do K[ii] := A[i]; ii := ii+1 end do end do;

> K1 := Matrix(1 .. n, 1 .. 1); ii := 1; for i to na do for j to nPe do K1[ii] := Pe[j]; ii := ii+1 end do end do; > K := Concatenate(2, K, K1);

# F contains an interpolation for any parameters within the range I specified in vectors A and Pe

> F := Matrix(n, datatype = float[8]); for i to n do for j to n do F[i, j] := evalf(1/sqrt(((K[i, 1]-K[j, 1])/A[na])^2+((K[i, 2]-K[j, 2])/Pe[nPe])^2+1)) end do end do;

> UF, SigF, VFt := SingularValues(F, output = ['U', 'S', 'Vt']); > SF := Vector(n); for i to n do SF[i] := 1/SigF[i] end do;

> SF := DiagonalMatrix(SF, n, n);

> Fpsinv := VFt^%T.SF.UF^%T;

> C := B.Fpsinv;

> Nodes := ImportVector(NodesTemp);

# f contains the interpolation for a specific case (in this case, the parameters from which the dataset "Nodes" is calculated)--Kguess is a 2 element vector containing these unknown parameters

> f := Vector(n); for i to n do f[i] := evalf(1/sqrt(((Kguess[1]-K[i, 1])/A[na])^2+((Kguess[2]-K[i, 2])/Pe[nPe])^2+1)) end do;

> ROM := evalf(Phi.C.f); > ObjectiveFunction := Vector(nn); for i to nn do ObjectiveFunction[i] := evalf((Nodes[i]-ROM[i])/Nodes[i]) end do;

> p := proc (Kguess) evalf(add(ObjectiveFunction[i], i = 1 .. nn)/nn) end proc;

> Optimization[NLPSolve](2, p, assume = nonnegative);

Error, (in Optimization:-NLPSolve) non-numeric result encountered

Let me know if there's some newbish mistake that I've made. :)

Page 1 of 1