Carl Love

Carl Love

28025 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

What is f:= 1 doing in your code?

If diff(f(x), x) = 1, then f(x) = x. It's a straight line. Then you plot x vs. diff(f(x),x), which is just a horizontal line. Furthermore, it should be plots:-odeplot.

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

To truly make a procedure inline, it should be declared with option inline:

P:= proc(N,F)
option inline, operator, arrow;
      seq(seq(`if`(F(i,j), [i,j], NULL), j= 1..N), i= 1..N)
end proc;

If you want to rewrite the fundamental operators, then you should be studying assembly language or maybe something even lower level than that. There is a relatively small (a few hundred) set of commands in Maple that are called "built in" or "part of the kernel". These are essentially the atoms of Maple programs. There is no point in trying to rewrite them in Maple itself: You'd only be using other atoms. Integer division (iquo) and remainder (irem) are kernel commands.

That being said, a fairly decent alternative to irem can be written as

Irem:= (n,d)-> n - trunc(n/d)*d:

That still uses a kernel procedure, trunc. But note that `*``-`, and `/` are also kernel procedures in Maple:

eval(`*`);

 

I don't know what Excel is doing with the ln(0), but Maple cannot handle it. Attempting ln(0) in Maple gives a division-by-zero error. I don't think that you can trust the Excel result obtained by including the [0,0] data point.

Statistics:-LinearFit is essentially the same as CurveFitting:-LeastSquares except that the former allows access to the summary statistics that can be used to compute R-squared (the coefficient of determination).

restart:
macro(S= Statistics):
X:=  < .5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5 >:
Y:=  < 3.25, 5.82, 7.50, 8.79, 9.83, 10.66, 11.35, 11.94, 12.46 >:
curve:= [1, ln(x)]:
Sol:= S:-LinearFit(curve, X, Y, x, output= solutionmodule):

The solution curve is
add(curve[k]*Sol:-Results(parametervalues)[k], k= 1..nops(curve));

n:= numelems(Y):

The R-squared statistic (coefficient of determination) is
Rsq:= 1 - Sol:-Results(residualsumofsquares)/S:-Variance(Y)/(n-1);

 

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;

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