Carl Love

Carl Love

28025 Reputation

25 Badges

12 years, 311 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

It is possible, with algcurves[parameterization], to get a single parameterization instead of four.

restart:
f1:= 3-2*x^2-y^2:  f2:= x^2+2*y^2:
(X,Y):= algcurves[parametrization](f1-f2, x, y, t)[];

Z:= eval(f1, [x,y]=~ [X,Y]):
evalf(Int(sqrt(diff(X,t)^2+diff(Y,t)^2+diff(Z,t)^2), t= -infinity..infinity));

                7.640395578

We can get the exact value of the integral via a trigonometric substitution. The integrand simplfies remarkably.

S:= simplify(eval([X,Y,Z], t= tan(s)));

Int(sqrt(simplify(add(diff(S[k],s)^2, k= 1..3))), s= -Pi/2..Pi/2);
value(%);

evalf(%);

                7.640395576

plots:-spacecurve(S, s= -Pi/2..Pi/2, linestyle= solid, axes= frame, thickness= 3);

 

Note that the coefficients of both derivatives are 0 at x=0, which is thus a singular point. Thus it is not proper to give initial conditions at that point.

Here is a way to automate this computation somewhat with Maple. For this to work it is important to use a consistent ordering of the letters in the variable names.

n, nC, nH, nB, nHB, nCB, nCH, nCHB:= 800, 224, 240, 336, 64, 80, 40, 24:
eval(add(cat('n', s[])*(-1)^irem(nops(s),2), s= combinat:-powerset([C,H,B])));
                      160

A:= <10,15>:
B:= <12,8>:
Req:= <100,100>:
LinearAlgebra:-LinearSolve(< A | B >, Req);

Here is a procedure to count the minimal number of transpositions to achieve a permutation. It does not error-check the input, i.e., it does not check that the first list has unique elements or that the second list is a permutation of the first.

Transpositions:= proc(L1::list, L2::list)
description "Count the transpositions in a permutation.";
local x, y, pos:= table(L1 =~ [$1..nops(L1)]);
     add(nops(x)-1, x= convert([seq(pos[y], y= L2)], disjcyc))
end proc:

Example of use:

Transpositions([w,x,y,z], [y,x,z,w]);

                   2

Here's my Maple implementation of the pseudo-code that you gave:

GreedyVertexColoring:= proc(G::GraphTheory:-Graph)
uses GT= GraphTheory;
local
     #Initialize colors to 0.
     Colors:= proc(v) option remember; 0 end proc,
     N, v, k
;
     for v in GT:-Vertices(G) do
          N:= map(Colors, {GT:-Neighbors(G,v)[]});
          for k while _C(k) in N do end do;
          Colors(v):= _C(k)
     end do;
     # Return remember table.
     op(4, eval(Colors))
end proc:

Example of use:

G:= GraphTheory:-SpecialGraphs:-PetersenGraph():
GreedyVertexColoring(G);

Colors:= table([_C(1)=red, _C(2)=green, _C(3)=blue]):
for v in GraphTheory:-Vertices(G) do
     GraphTheory:-HighlightVertex(G, v, Colors[C[v]])
end do:
GraphTheory:-DrawGraph(G);

I'll do this one because there are some idiosyncratic-to-Maple stumbling blocks to getting the proof.


restart:

Part a) Estimate the differences....

sys:= {u(n+1)=1/2*(u(n)+2/u(n)), u(0)=1}, u(n):

U:= rsolve(sys, makeproc):

seq(evalf[50](U(k)-sqrt(2)), k= 3..6);

0.21239014147551198799032412823135871908697211e-5, 0.15948618246068546804368315468877467388e-11, 0.8992928321650453100503993e-24, 0.3e-48

Part b) What can we conjecture? Obviously that the sequence converges to sqrt(2).

Part c) How to prove that with Maple?

U:= rsolve(sys);

2^(1/2)*coth(arccoth((1/2)*2^(1/2))*2^n)

evalc(U);

2^(1/2)*sinh(arctanh((1/2)*2^(1/2))*2^n)*cosh(arctanh((1/2)*2^(1/2))*2^n)/(sinh(arctanh((1/2)*2^(1/2))*2^n)^2+sin((1/2)*Pi*2^n)^2)+I*2^(1/2)*sin((1/2)*Pi*2^n)*cos((1/2)*Pi*2^n)/(sinh(arctanh((1/2)*2^(1/2))*2^n)^2+sin((1/2)*Pi*2^n)^2)

simplify(%) assuming n::posint;

2^(1/2)*cosh(arctanh((1/2)*2^(1/2))*2^n)/sinh(arctanh((1/2)*2^(1/2))*2^n)

limit(%, n= infinity);

2^(1/2)

 


Download sequence.mw

You almost have it. Your problem is that there is no need for any looping command. Some local variables will help also.

First_Principle:= proc(f::appliable)
local x, h, A:= simplify((f(x+h)-f(x))/h);
     Limit(A, h = 0) = limit(A, h = 0)
end proc:

Example of use:

First_Principle(sin);

You can remove from the solutions those for which the evaluation of leads to error like this:

Error:= proc() error NumericException(division_by_zero) end proc:
NumericEventHandler(division_by_zero= Error):
CheckSolution:= proc(sol::set(name=anything))
     try
          eval(R, sol)
     catch "numeric exception: division":
          return true
     end try;
     false
end proc:

remove(CheckSolution, sols);

Nothing special is required because of the change of version. Just open it as you would open any other file.

You can discard randomly generated values that don't work, like this

restart:
M:= Array([[a+2*b,b],[x1+y1,z1+z2]]);
pars:= indets(M);
npars:= numelems(pars);
ntrials:= 20:
myRand:= RandomTools:-Generate(list(float(range= -3..3), npars), makeproc):

to ntrials do
     do
          set1:= pars=~ myRand();
          numM:= eval(M, set1);
          if andmap(x-> 0 < x and x < 1, numM) then break end if
     end do;
     LinearAlgebra:-Rank(numM)
end do;

The above takes an average of about 1600 random trials to find each matrix that works.

Apparently the KroneckerProduct command does not work with matrices that have index functions. You need to convert your shape= Circulant matrices to shape= rectangular like this:

A1:= Matrix(A, shape= rectangular):
B1:= Matrix(B, shape= rectangular):
KroneckerProduct(A1,B1);

You may be able to get what you want from ToInert. For example,

ToInert(A = B*C);

odeplot is in the package plots, so you need to refer to it as plots:-odeplot. Or, you load the package with

with(plots):

Then you can refer to the commands in the package without using the plots:- prefix.

PDEtools:-dchange(
     {x(t)= r(t)*cos(theta(t)), y(t)= r(t)*sin(theta(t))},
     {
          diff(x(t),t) = x(t)*y(t)-x(t)^2*y(t)+y(t)^3,
          diff(y(t),t) = y(t)^2+x(t)^3-x(t)*y(t)^2
     },
     {r(t), theta(t)}
);

solve(%, {diff(r(t),t), diff(theta(t),t)});

simplify(%);

First 286 287 288 289 290 291 292 Last Page 288 of 395