Carl Love

Carl Love

28095 Reputation

25 Badges

13 years, 100 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

The way to think about this is to put the equation is the canonical form x^2/a^2 + y^2/b^2 = 1. Then the parametric curve is x = a*cos(t), y = b*sin(t), 0 <= t <= 2*Pi.

eq:= 0.3939708949*x^2 - 0.005975799853 + 0.6345432059*y^2:
a:= coeff(eq, x^2):
b:= coeff(eq, y^2):
r:= -tcoeff(eq):
plot([sqrt(r/a)*cos(t), sqrt(r/b)*sin(t), t= 0..2*Pi], scaling= constrained);

I've come up with a solution to the parentheses issue...mostly. I can replace the high-precedence operator &= with the low-precedence operator <~ (it can also be <=~ if you prefer). The new operator is lower precedence than all the arithmetic operators, but higher precedence than the logical operators and, or, etc. So, you would be able to do

x <~ a+b;

but

x <~ (a and b);

would still require parentheses. That's the "mostly". But that eliminates the use of extra parentheses for the vast majority of normal expressions that would appear on the RHS of an assignment statement.

Since <~ has a predefined value (whereas &= does not) as an elementwise operator, this is a bit trickier to code than the previous solution. Overriding the value of an elementwise operator is especially tricky since they are all handled through the single builtin procedure `~`. We have to do it in such a way that it does not affect all the other uses of elementwise operators. And we have to deal with the special ` $` argument that is passed to calls to elementwise operators (see ?elementwise ).

restart:

local `~`:= proc(f::uneval, `$`::identical(` $`), expr::uneval)
local x, opr:= op(procname);
     if opr <> `<` then  return :-`~`[opr](args)  end if;
     x:= eval(expr);
     print(op(1,
          subs(
               _F_= nprintf("%a", f), _X_= x,
               proc(_F_:= expr=_X_) end proc
          )
     ));
     assign(f,x)
end proc:

r1:= 10:  r2:= 20:
x <~ r1 + r2;

If a function is going to be iterated with @@, then the number of inputs must equal the number of outputs.

Trivial example:

F:= (x,y)-> (x+y, x-y):
(F@@5)(1,2);

See ?elementwise . Read the ninth paragraph of Description, the one beginning "Expression sequences...." And note that the end-of-parameters marker is handled internally as ` $`, exactly the same as the fencepost character used when elementwise operators are applied to expression sequences.

See ?fracdiff

For example

fracdiff(x^2+x^3, x, 1/2);

interface(prompt= "> ");

Put whatever you want in the string, of course.

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.

 

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