Maple 12 Questions and Posts

These are Posts and Questions associated with the product, Maple 12

I have 6 parameters, say p1 - p6, which enter my Monte Carlo Code and computes a 1-D Array of floats of size 1000 . I have an experimental array of floats of the same size. My code outputs an array which is the difference of these two arrays. The objective function is the sum of the sqares of the elements in this output array. I have initial guess for the parameters: p1i - p6i. I need to find the values of the 6 parameters which minimize the objective function.

Obviously I do not have an explicit mathematical form for the objective function and nor its Jacobian.

Could some one please help me in this task.  Thanks in advance. 

I have a spike train which is a series of time points, for example saved as a vector of floats. Could someone tell me how I can plot this spike train as a series of vertical bars at each of these time points ?

I would also like to know how to plot a series of spike trains one above the other[i.e. the raster plot] if I start with a 2-D matrix of floats where each row correspond to one spike train.

Thanks in advance.

  

This should be a simple problem, but I am having trouble resolving a contradiction in integral evaluation that is included in the results below.  Instead of butting my head further perhaps someone can point out my probable error.

You will see in both cases I have a triangle signal with a slope of (-1).  However in the 2nd case I have linked the period T to the slope parameter alpha.  If I assign alpha=1 then the results of the 2 integrals should = 1/4, but the 2nd one does not.

Appreciate any feedback.


 

plot(piecewise(-1 < x and x < 0, 0, 0 < x and x < 1, 1-x), x = -2 .. 2, linestyle = solid, thickness = 5, scaling = constrained, title = "Asymmetric Triangle Wave", titlefont = [COURIER, 18])

 

n := 0; 1; T := 2; 1; a[0] := (int(0*exp(-I*(2*Pi*n*t/T)), t = -(1/2)*T .. 0)+int((1-t)*exp(-I*(2*Pi*n*t/T)), t = 0 .. (1/2)*T))/T

1/4

(1)

restart

alpha := 1; T := 2/alpha; plot(piecewise(x < 0, 0, 0 < x and x < (1/2)*T, -alpha*x+1), x = -T .. T, linestyle = solid, thickness = 5, scaling = constrained, title = "Asymmetric Triangle Wave", titlefont = [COURIER, 18])

 

  n=0 term:n := 0; 1; alpha := 1; 1; T := 2; 1; a[0] := (int(0*exp(-I*(2*Pi*n*t/T)), t = -(1/2)*T .. 0)+int((1-alpha*T)*exp(-I*(2*Pi*n*t/T)), t = 0 .. (1/2)*T))/T

-1/2

(2)

``


 

Download integral_contradiction.mw

I am seeking the limit of a series representation of a waveform to within so many significant figures.  Unfortunately, as the series contains more & more terms the demands on computation memory become a problem.  Perhaps there is a method within MAPLE I am not familiar with that can possibly circumvent this problem?

Below is the link to my worksheet.  The presumed theoretical limit is supposed to be 0.0894945 (this is based on what I have read)  (perhaps it may be wrong).  So far I have 3 of the sig figs agree, but would like to take it further.  Is this possible with different MAPLE commands than what I am currently employing?  Currently, MAPLE crashes if I venture beyond 100000 terms in the series.

seeking_the_limit.mw

I was recently cleaning up a worksheet to make things more succinct.  In that process I modified how I expressed the series coefficients, Ck.  What seemed to be an innocous change apparently upset MAPLE to the point it cannot process my results.  In the abbreviated worksheet link below I process the results in the previous manner, Ck1, as opposed to my current modification, Ck2.

In the previous manner the results are generated under 3 minutes.  After modifying the expression for Ck, MAPLE cannot seem to process the results at all.  As far as I can tell the Ck1 & Ck2 concur.  So I am perplexed.  Can anyone see what is wrong?  The only thing I can think of is that sin(2*pi*k/T*x) in the denominator might cause the problem.  However, the sin term is cancelled out by the same sin term in S4.

Ck_modification.mw

I originally posted this question @ Reconciling roots of a series  However, I got no responses.  I have done further work on the problem & attempted to delete my original posting to initiate this one.    I did not see the option to delete Reconciling roots of a series.  So if any website moderator can delete the original & leave this one stand that would be helpful.  The results in this posting are more illuminating.

I have an infinite series that is function of


                                   /2 Pi k x\
                               sin|--------|
                                     \   T    / where k is the frequency parameter that is an integer value from 1 to m.  The series is also linearly dependent on the coefficient, Ck.  However, Ck is nonlinear with respect to k.  3 other parameters are undefined, a0, N, & tau.  Taking the derivative of the series removes the constant a0 & the factor (2 Pi k)/T comes out of the sin term & the sin term bcomes a cos term.  N is a positive integer & tau is a real #, generally between 0 & 1.

The derivative of the series can be evaluated since Ck falls of by 1/k^2 which renders the factor (2 Pi k)/T to (2 Pi)/T.  All is well & MAPLE seems to confirm that by the result (5).  I then attempt to find the roots of the derivative after defining the values for m, a0, N, & tau with both the solveRootFinding:-Analytic commands.  The results from the 2 do not seem to coincide.

I then repeat the process with chek2.  Now there seems to be some overlap in the results.  But as I pointed out in Reconciling roots of a series in the case of chek the series parameters m, a0, N, & tau have not been assigned values.  In the case of chek2 those parameters do have assigned values; hence, the solution characteristics are different for the solve command, but not for RootFinding:-Analytic.

In a different problem, but somewhat related someone pointed out the superior computational performance of the RootFinding:-Analytic as opposed to the solve command.  The results here if I interpret them correctly suggest that the solve command can be WRONG altogether.  Can this be explained in a concise & coherent manner that most users can follow?  Also, solve can produce an analytic expression as opposed the RootFinding:-Analytic command.  Is there a way to use the RootFinding package to produce an analytical result?  In the case presented below I suppose the analytic result for solutions to chek would be JUNK?

reconcile_solns.mw

I employed the sort command to sort through 10 solutions to a series of order 10.  However, I do not follow the logic of the output.  So I attempted to sort by ascending order by the magnitude, but I am getting errors which I am having trouble circumnavigating.  Can show me how to sort my solutions properly?

The worksheet is in my reply below.

1.

with(Groebner):
K := {r-x^4,u-(x^3)*y,v-x*y^3,w-y^4};
G := Basis(K, 'tord', degrevlex(r,u,v,w));
R1 := eliminate(G, {r,u,v,w}); # eliminate is the reverse of Basis
Ga := Basis({a*G[1],a*G[2],a*G[3],a*G[4],a*G[5],a*G[6],a*G[7],a*G[8],a*G[9],a*G[10],a*G[11],a*G[12],a*G[13],a*G[14], (1-a)*K[1], (1-a)*K[2], (1-a)*K[3], (1-a)*K[4]}, 'tord', deglex(a,r,u,v,w));
Ga := remove(has, Ga, [x,y,a]);
eliminate(Ga, [r,u,v,w]);

how to eliminate Ga to find back K ?

2.

A1A2 and A3A4 parallel
A(0,0), B(u1,0), D(u2,u3), C(x1,x2), E(x3,x4)
#BC = A1A2
xx1 := u1:
xx2 := x1:
yy1 := 0:
yy2 := x2:
#AD = A3A4
xx3 := 0:
xx4 := u2:
yy3 := 0:
yy4 := u3:
eq1 := (xx2 - xx1)*(yy4 - yy3) - (yy2 - yy1)*(xx4 - xx3);
(x1-u1)*u3-x2*u2;
#CD = A1A2
xx1 := x1:
xx2 := u2:
yy1 := x2:
yy2 := u3:
#AB = A3A4
xx3 := 0:
xx4 := u1:
yy3 := 0:
yy4 := 0:
eq2 := (xx2 - xx1)*(yy4 - yy3) - (yy2 - yy1)*(xx4 - xx3);
-(u3-x2)*u1;
with(LinearAlgebra):
#E is on the same line of AC
xx1 := x3:
yy1 := x4:
xx2 := 0:
yy2 := 0:
xx3 := x1:
yy3 := x2:
eq3 := Determinant(Matrix([[xx1,yy1,1],[xx2,yy2,1],[xx3,yy3,1]]));
-x3*x2+x1*x4;
#E is on the same line of BD
xx1 := x3:
yy1 := x4:
xx2 := u1:
yy2 := 0:
xx3 := u2:
yy3 := u3:
eq4 := Determinant(Matrix([[xx1,yy1,1],[xx2,yy2,1],[xx3,yy3,1]]));
-x3*u3+u1*u3-u1*x4+u2*x4;
 

sol := eliminate({eq1,eq2,eq3,eq4},[x1,x2,x3,x4]);

with(Groebner):
K := {(rhs(sol[1][1])-lhs(sol[1][1])),(rhs(sol[1][2])-lhs(sol[1][2])),(rhs(sol[1][3])-lhs(sol[1][3])),(rhs(sol[1][4])-lhs(sol[1][4]))};
G := Basis(K, 'tord', degrevlex(x1,x2,x3,x4));
R1 := eliminate(G, {x1,x2,x3,x4}); # eliminate is the reverse of Basis
Ga := Basis({a*G[1],a*G[2],a*G[3],a*G[4], (1-a)*K[1], (1-a)*K[2], (1-a)*K[3], (1-a)*K[4]}, 'tord', deglex(a,x1,x2,x3,x4));
Ga := remove(has, Ga, [u1,u2,u3,u4,a]);

From Question1, is it possible to find from sol to eq1, eq2, eq3 and eq4 ?

For example

if x*y*z+ x*y^2

after filter 

x*y*z

I have resolved the roots of a series both numerically & analytically.  Let me qualify numerical  versus analytical.  Analytically I evaluate the series without substituting values for the various parameters of the series.  I then differentiate the series, then substitute in the appropriate parametric values, & then solve.  By this method I obtained 5 complex roots.

The numerical approach has values already assigned to the parameters of the series.  I then differentiate & solve.  I obtain only REAL roots in this instance.  I then restricted these results to obtain the solution I believe to be correct given by result (7).

I cannot seem to steer the solver in the analytic case to obtain the correct REAL result that I am expecting.  Can anyone help on this?

Before any website moderator thinks this is the same question as Error-in-Isinternal-Too-Many-Levels, it is not.  I have resolved that question.  This is a different question, but on the same problem!

reconcile_solns.mw

i have two functions , first naive function has error after used.
 
if run FromMatlab, does it mean that do not need to copy the result and run again because it had already run?
as i do not understand the output code after translated.
 
there is syntax error when translate second function
 
with(Matlab):
FromMatlab("function X = sylv_naive(A,B,Q)
% X=SYLV_NAIVE(A,B,Q) solves the Sylvester equation AX + XB = Q
%    A, B, Q: matrix coefficients
%    X : solution of AX + XB = Q
[m,n] = size(Q);
H = kron(eye(n), A) + kron(B.', eye(m));
Qvec = reshape(Q,m*n,1);
Xvec = H\Qvec;
X = reshape(Xvec,m,n);
");
sylv_naive(Jesus7,Jesus7,Matrix([[0,0],[0,0]]));
sylv_naive(Jesus7,Jesus7,Matrix([[0],[0]]));
Error, (in ArrayTools:-Reshape) the desired output contains a different number of elements than the input
 
 
 
with(Matlab):
FromMatlab("function X = sylvester(A,B,Q)
% X=SYLVESTER(A,B,Q) solves the Sylvester equation AX + XB = Q
% by using the Bartels and Stewart algorithm based on the complex
% Schur decomposition
%    A, B, Q: matrix coefficients
%    X : solution of AX + XB = Q
[m,n] = size(Q);
[U,A1] = schur(A,'complex');
[V,B1] = schur(B.','complex');
Q1 = U'*Q*conj(V);
X = zeros(m,n);
X(:,n) = (A1 + B1(n,n)*eye(m))\Q1(:,n);
for i = n-1:-1:1
    v = Q1(:,i) - X(:,i+1:n)*B1(i,i+1:n).';
    X(:,i) = (A1 + B1(i,i)*eye(m))\v;
end
X = U*X*V.';");

Error, (in Matlab:-FromMatlab) on line 15, syntax error
    X(:,i) = (A1 + B1(i,i)*eye(m))
 
 

if known solution [a,b,c,d]

solve([eq2, eq3, eq4, ....], [a,b,c,d])

but not equal to known solution a,b,c,d even if number of equations more than number of variables.

then guess that there are some necessary and sufficient conditions unknown.

how to find the necessary and sufficient conditions from solutions?

is there options to set for this?

or can eliminate function help to find necessary and sufficient conditions and how to do?

 

 

 

Error, (in is/internal) too many levels of recursion

I get the error above when attempting to solve for the roots of partial derivative.  My results are below:


 

S3 := -(1/2*I)*(-(2*I)*exp(I*Pi*k*tau/T)*Pi*k-exp(I*Pi*k*tau/T)*T+I*exp(I*Pi*k*tau/T)*Pi*k*tau+(4*I)*Pi*k-(2*I)*exp(-I*Pi*k*tau/T)*Pi*k+exp(-I*Pi*k*tau/T)*T+I*exp(-I*Pi*k*tau/T)*Pi*k*tau)*sin(2*Pi*k*x/T)/(Pi^2*k^2)

S3 = ((-I)*(1/2))*((I*Pi*k*tau-(2*I)*Pi*k)*(exp(I*Pi*k*tau/T)+exp(-I*Pi*k*tau/T))-T*(exp(I*Pi*k*tau/T)-exp(-I*Pi*k*tau/T))+(4*I)*Pi*k)*sin(2*Pi*k*x/T)/(Pi^2*k^2)
"(->)"true"(->)"true

Despite the the simplifications MAPLE generated above MAPLE does not recognize the expressions as being equivalent.  So set the following for the Fourier coeffs:NULL

Ck := (-I*((2*(I*Pi*k*tau-(2*I)*Pi*k))*cos(Pi*k*tau/T)-(2*I)*T*sin(Pi*k*tau/T)+(4*I)*Pi*k))*(1/(2*Pi^2*k^2))

-((1/2)*I)*(2*(I*Pi*k*tau-(2*I)*Pi*k)*cos(Pi*k*tau/T)-(2*I)*T*sin(Pi*k*tau/T)+(4*I)*Pi*k)/(Pi^2*k^2)

(1)

The Fourier series can now be expressed as a 1 sided series employing both the Sum vs sum vs add commands for comparison:``

T0 := kernelopts(cputime), time(), time[real]();

204175839, 9435456, 8.998352053

(2)

S7 := a[0]+Sum(Ck*sin(2*Pi*k*x/T), k = 1 .. m):

1600991, 0, 0.

(3)

solve([diff(S5, x) = 0, 0 < x, x < 10*T/(2*Pi*m)], x)

Error, (in is/internal) too many levels of recursion

 

solve([diff(S5, x) = 0, 0 < x, x < 1/8], x)

Error, (in is/internal) too many levels of recursion

 

``


 

Download 2_many_levels_of_recursion.mw

I have been attempting to resolve a particular problem to which I have posted a number of questions in the past.  In my attempts I have stumbled onto a number of command syntax issues & inconsistent result outputs.  Each time I try to post questions that appear to me to be separate questions even though it pertains to the same problem.  On numerous occasions a website moderator has deleted my questions unilaterally because the moderator has the opinion the question is identical to a previous question.

Deleting my questions instead of placing them into a previous thread without a response impedes my progress.  I am going to repost this inconsistent output, ONCE again!  If it is directly related to another thread then notify me of the response somehow instead of simply deleting the question.

The following inconsistency as far as I can tell is not explained in any of my previous questions.  I have a series that represents a particular waveform.  The series representation gives a definitive output.  However, when attempting generate the series of the derivative of this waveform (Q3 & Q4), which does exist (Q1 & Q2), MAPLE chokes on that representation & simply continues to evaluate for days & weeks without generating an output.  Why is this?  If anyone gets a definitive result please post it so that I might be able to reproduce the results.

Thanks in advance.

inconsistent_results.mw

Is it possible to use Regex to generate a complete list of patterns?

for search pattern in a list of characters

5 6 7 8 9 10 11 Last Page 7 of 29