Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

I cannot follow your English, your notation, or your formatting close enough to check your work, your truth tables. However you can easily check them yourself using Maple's Logic package. Example:

with(Logic):
`&->`:= `&implies`:
`&<->`:= `&iff`:
`&^`:= `&and`:
`&v`:= `&or`:

MP:= (A,B)-> B &-> A:
Tautology(MP(p,q) &<-> MP(&not q, &not p));

                                                           true

The corrected version of your procedure returns eval(expr):

f:=proc()
local z,x,expr;
     expr:=3*z;
     z:=solve(x-1=0,x);
     eval(expr)
end proc:

You violated precisely the rule expressed in the paragraph which you thought wasn't in plain English: expr was only evaluated to a single level. You might find this explained more clearly at ?eval . Let me know.

 

You need to follow the anonymous procedure definition with a ( ) to invoke it. Otherwise, the whole procedure definition becomes the return value of the if statement (if that branch is taken). (The body of the if statement is indeed being called in your example.) Example:

f:= proc()
local x:= 9;
     if x < 10 then
          proc()
          local z:= 20;
               x:= z
          end proc
          ()    
     end if;
     x
end proc:

f();                                                    
                                            20

I use this technique fairly often in my code. It is especially useful when you want to execute the inner procedure in the evalhf environment. The () can go right next to the end proc if you want; my style is to place in on its own line to clearly distinguish it from a procedure-as-return-value.

Maple calls them keyword parameters. They are heavily used in library code. See ?parameter_classes . Example:

Foo:= proc({Arg_1::integer:= NULL, Arg_2::float:= NULL})
     Arg_1+Arg_2
end proc:
Foo(Arg_1 = 3, Arg_2 = 0.5);
                                                          
3.5

I don't really the understand the question as posed by your prof, but I do understand what you were trying to do with your code. Here's how to actually do it. Only one command is required.

plots:-contourplot(x^2-2*y^2, x= -5..5, y= -5..5, contours= [seq(C, C= -5..5)]);

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.

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