Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

I am using Maple notation for the logical operators.

p implies q is equivalent to not p or q, whether p and q are considered to be boolean variables, or they are considered to be boolean propositions. This is how implication is expressed in terms of conjunction (and), disjunction (or), and negation (not). Entailment can be considered to be a generalization of implication whose left argument is a set, possibly empty, of propostions. Let S be a set of propositions and let p be a proposition. Then Entail(S,p) is equivalent to `and`(S[]) implies p which is equivalent to not `and`(S[]) or p. Thus, entailment is expressed in terms of conjunction, disjunction, and negation. If S is the empty set, that simplifies to simply p.

 

Why do you want to write this procedure? to learn programming? to learn about Maple? to learn about primes?

You only need to try divisors up to the square root of n. (You should prove that for yourself.) See ?isqrt . After 2, you only need to try odd divisors. Your flr is the equivalent of Maple's iquo, which is thousands of times faster. See ?iquo . Checking whether one integer is divisible by another is equivalent to checking that the remaider of the division is 0. See ?irem . Once you've determined that n is composite, it's just a waste of time to stay in the loop. See ?return and ?break .

Here's a decent primes-by-trial-division procedure:

Isprime:= proc(n::posint)
local d;
     if n=2 then return true end if;
     if n=1 or irem(n,2)=0 then return false end if;
     for d from 3 by 2 to isqrt(n) do
          if irem(n,d)=0 then return false end if
     end do;
     true
end proc;

But a trial-division procedure will never get close to the speed of Maple's isprime. It will take you years of study to understand how and why isprime works.

See ?DEtools,convertsys .

Example:

DEtools[convertsys]({diff(y(x),x$2) = y(x)}, {y(0)=1, D(y)(0)=0}, {y(x)}, x);

I use these special keystrokes constantly in my Maple worksheet typing:

  • Ctrl-J: Insert execution group below cursor.
  • Ctrl-K: Insert execution group above cursor.
  • Ctrl-T: Switch from executable code mode to text mode (for entering extended formatted comments).
  • Ctrl-M: Switch from text mode to executable code mode.
  • Shift-Enter (or Shift-Return): Begin a new line in the same execution group.
  • Func-3: Split execution group into two (at cursor).
  • Func-4: Join cursor execution group with execution group below.

I very rarely use menu commands. I think that the Ctrl-J and Ctrl-T are the primary things to address your specific problem.

 

AlternateDiagonalTranspose:= proc(M::Matrix(square))
local N:= op([1,2], [rtable_dims(M)]);
     Matrix(N, N, (i,j)-> M[N-j+1,N-i+1])
end proc:
AlternateDiagonalTranspose(Matrix([[1,0,0],[1,0,0],[0,0,0]]))^%T;

TrueIndices:= (N,F)-> [seq(seq(`if`(F(i,j), [i,j], NULL), i= 0..N), j= 0..N)];

fulfills the requirements of your exercise, although I'd still prefer to make it a proc so that I could declare i and j local.

series(sin(x)^cos(x), x= Pi) indicates that it does not converge. There is a (x - Pi)^(-1) term.

Assuming that p(x), q(x), r(x), a, b, alpha, and beta are suitably defined, then it is done like this:

restart:
p:= x-> x+2:  q:= x-> x:  r:= x-> 1:
a:= 0:  b:= 1:  alpha:= 0:  beta:= 1:
dsolve({diff(y(x),x$2)= p(x)*diff(y(x),x)+q(x)*y(x)+r(x), y(a)=alpha, y(b)=beta}, y(x));

The symbolic answer to this example is too long to copy here.

If you want a numeric, rather than symbolic, solution, then just change the last line to

dsolve({diff(y(x),x$2)= p(x)*diff(y(x),x)+q(x)*y(x)+r(x), y(a)=alpha, y(b)=beta}, y(x), numeric);

 

To do what you want, you would need to know the correspondence between the lettered column names in Excel and the numbered columns in the Maple Matrix. Once you know that, the rest is absolutely trivial. So, do you know what numbers corresponds to columns A and AB?

Let's say A=1 and AB=27. Then do

MediaRighe(M[1..15, 1..27]);
MediaColonne(M[1..15, 1..27]);

Note that your procedures duplicate the work done by the Statistics:-Mean command. Your call to MediaColonne (to get the columnwise means) could be replaced by

M:= subs("-"= undefined, M):
Statistics:-Mean(M[1..15, 1..27], ignore);

And, after that, your call to MediaRighe (to get the rowwise means) could be replaced by

Statistics:-Mean(M[1..15, 1..27]^%T, ignore);

The same is true for all the other dataset summary statistics, such as StandardDeviation.

 

To get the slope, you extract the points from the plot, then you use linear least-squares regression on the logarithms of the points. Here's an extended example:

 

restart:

Digits:= 15:

f:= (t,y)-> I*y:

Exact:= unapply(rhs(dsolve({diff(y(t),t) = f(t,y(t)), y(0)= -I})), t);

(1)

Mid:= proc(h::{positive, realcons})
local
     y0:= -I, #Initial condition
     t,
     y1:= evalf(y0+h/2*(f(0,y0)+f(h, y0+h*f(0,y0)))), #one step of Heun
     y2
;
     for t from h by h to 1 do
          y2:= y0 + 2*h*f(t,y1);
          y0:= y1;
          y1:= y2
     end do;
     #Return the error
     evalf(abs(Exact(t-h)-y0))
end proc:
          

plots:-loglogplot(Mid, 1e-5..1e-1, labels= [h, `error`]);

 

Extract points data matrix from the plot.

XY:= op([1,1], %);

(2)

To get the slope of the line, perform linear least-squares regression on the logarithms of the points data.

Statistics:-LinearFit([1,x], ln~(XY), [x]);

(3)

So the slope is the coefficient of x.

 

Download Midpoint_error.mw

The unusual form of the solution is due to gamma's special role as a constant. Although I don't know the exact reason for the mysterious appearance of I in the solution, I do know that it can be avoided by declaring gamma as local:

restart;
local gamma;
gamma = 1/sqrt(1-beta^2);
solve(%, beta
);

It is very difficult for me to read the MapleMath "font" of this website. It would best if you didn't use it and just used plaintext instead. Too bad that we don't have MathJax (a LaTeX subset used on many websites). I think that what you've entered is the arclength formula:

int(sqrt(1+diff(f(x), x)^2), x= 0..17)

Is that correct?

I presume that your function f(x) is real valued. Is that correct? Then the imaginary part is spurious, perhaps the result of evaluating an elliptic function in the symbolic antiderivative.

You'll very likely get faster, more accurate, and entirely real results if you use numeric integration:

evalf(Int(sqrt(1+diff(f(x), x)^2), x= 0..17));

Note that Int is with an uppercase I for numeric integration.

If the total number of index values (i.e., mul(k_||j+1, j= 1..n)) is small enough that the Cartesian product can easily fit in memory (say, less than 10-100 million), then a non-iterated solution is probably much faster. Here's one:

CartProdSeq := proc(L::seq(list))
local Seq,i,j;
option `Copyright (C) 2007, Joseph Riel. All rights reserved.`;
     eval([subs(Seq= seq, foldl(Seq
                              , [cat(i,1..nargs)]
                              , seq(cat(i,j)=L[j],j=nargs..1,-1)
                             ))]);
end proc:

#K:= [k1, ..., kn]:
K:= [2,3,4]:
add(f(i[]), i in CartProdSeq(seq([$0..kj], kj in K)));

While the example seems silly to me, the output seems no more jumbled than any other polynomial in Maple. Polynomials are not generally sorted by powers in Maple.

Let expr be your arbitrarily complicated expression. Then

evalindets(expr, realcons, evalf[30]);

First 316 317 318 319 320 321 322 Last Page 318 of 395