Carl Love

## 24322 Reputation

9 years, 353 days
Natick, Massachusetts, United States
My name was formerly Carl Devore.

## copy(g) ?...

After executing the statement

gn:= g;

gn is identical to g, so any changes made to gn will automatically be made to g also. To avoid this, i.e. to create a separate independent matrix, use copy:

gn:= copy(g);

But I can't tell for sure if this is what you need because you never use gn after constructing it. So the only way that the code as posted makes sense is if the changes are made to g. Perhaps you didn't upload the whole code.

Also, the double if statement at the end can be replaced by

if not (j in s[i] xor n in s[i]) then g[j,n]:= 0 end if;

## ::`+`, nops, op, indets, and degree...

To avoid unintended conversion of monomials, you can check if the expression is of type `+`.

Example:

 > p:= randpoly([x,y,z]); > evalb(p::`+`); > `if`(p::`+`, nops, 1)(p); > L:= `if`(p::`+`, [op], `[]`)(p); > tL:= indets ~ (L); > nL:= nops ~ (tL); > [seq]({seq}(v=degree(L[k],v), v= tL[k]), k= 1..nops(L)); ## eval...

You simply need to do

eval(x(t), dsn1(1));

Let me know how that goes.

## Go one step backwards before going forwa...

Building upon Markiyan's excellent observation about erf (which I wish I could vote up, but can't because it's a comment), we see that the Asker's original problem can be done thus (which I call going one step backwards before going forward):

 > restart;
 > f:= exp(-(x+sigma)^2/2/sigma^2); > diff(int(f,x), x\$(n+1)); And also we see that Maple's algorithm for arbitrary order differentiation could be very easily improved. It would be trivial for it to check this method after other methods have failed.

## Fencepost error...

You've made the classic so-called fencepost error. Think of the trapezoids as the gaps between posts of a fence, and think of the evaluation points as the fenceposts. There are n of gaps, hence n+1 posts. In your CompTrap, you have n+2 evaluation points: a, b, and n done in the loop. The loop needs to stop at n-1.

Also, in your test comparison integral, you are integrating from 8 to 1. You should go from 1 to 8.

You can compare your procedure with Maple's own trapezoid rule procedure like this: The call

CompTrap(f, a, b, n);

should produce the same result (*footnote) as

Student:-Calculus1:-ApproximateInt(f(x), x= a..b, method= trapezoid, partition= n);

This is a good way to test whether your procedure is correctly implementing the rule.

It is also good to compare against the integral done by Maple's more sophisticated methods, as you did. This is a way of testing whether the rule itself is good, not testing your implementation of it. You can also study the rate of convergence of the rule.

A matter of style in your procedure: Be careful of how you mix "pure" exact symbolic computation with floating-point numeric computation. Your procedure has 0.5 near the end. You should probably change that to exact (1/2).

Regarding your Simpson's Rule procedure: In addition to the fencepost error, there five other errors in that, three algorithmic and two syntactic. Two of the algorithmic errors are super obvious and the third is subtle; both syntactic errors are essentially the same. If you find any two of the five, I'll point out another two. Deal? Also, why did you change the parameter n from the trapezoid procedure to j in the Simpson's procedure? Maple doesn't care which you use, but the change may have clouded your thinking and led to one of the errors.

You can test/compare your procedure with Maple's own implementation of Simpson's rule by using the same Student command as above, but changing trapezoid to simpson.

(*footnote): After you apply evalf, there may be a small deviation due to rounding error. This may affect the last digit.

## Unevaluated functions in Maple...

You were close. That's actually fairly impressive for one's first day with Maple (and the day is young in my time zone).

An unevaluated function does need to have at least a name, something to put immediately in front of the (a, b, c, d). You are right that no explict expression or -> is needed. I think from your example that you want to name it B. Do this:

restart;
mtaylor(B(a,b,c,d), [a=e,b=f,c=g,d=h], 2);

Does that give you what you want? I made the order 2 because 1 is too trivial an example for you to see what Maple is doing. Please feel free to followup here on MaplePrimes. Have fun exploring Maple.

## Old-fashioned...

@iazaroff I wasn't suggesting that you switch to Maple Input permanently. Rather, I was asking as a means of testing what was wrong with your particular system. But it's fine with me if you do switch to Maple Input. I never use 2D Input myself, and I find that it's much harder to answer other users' questions if they use it.

Someone else who is more adept with the 2D Input than I am can probably fix your problem. However, If you're happy with the Maple Input, you can do as I do and make it the default: Go to the Tools Menu, then select Options, then the Display tab. In the top box, select Maple Notation, then click Apply Globally at the bottom.

## It doesn't simplify...

That one does not simplify. But that is not analogous to your first example: This second example has a product of two square roots in numerator; the first has a single square root in the numerator. In general, sqrt(a)*sqrt(b) <> sqrt(a*b). If I make this small change in your second example (combining the square roots in the numerator), it will simplify to 1 without using assumptions.

I can't find a set of assumptions that will work on your second example. I'll admit that's a deficiency of the assumption facility. But I can force the potentially invalid rule (although it's perfectly valid if everything under a radical is positive) by using applyrule like this:

 > ex:= (g*a^2+2*2^(1/2)*E^(1/2))^(1/2)*(-g*a^2+2*2^(1/2)*E^(1/2))^(1/2)/(8*E-g^2*a^4)^(1/2); > ex2:= applyrule(sqrt(A::algebraic)*sqrt(B::algebraic)= sqrt(A*B), ex); > simplify(ex2); > expand(ex2); >

Note that this is valid for any E.

## Try input mode Maple Input....

@iazaroff Hmm. I guessed wrong.  Try this: use the pull-down menu to change the input mode from "2D Input" to "Maple Input". Then, at the red "> ", type explicitly (i.e. do not use the palettes)

sin(Pi/4);

(including the semicolon), and then press return (or enter). The characters you type should appear in red boldface. Maple should respond 1/2*sqrt(2), but it should be in the usual mathematical notation, and it should be in blue.

Let me know how that goes.

## My simplify works, and with no assumptio...

If I apply simplify or even expand to your expression, it simplifies to 1 with or without any assumptions. I'm using Maple 16. What version are you using?

## Are you using parentheses?...

Are you using parentheses? Unlike standard mathematical notation, functions like sin, ln, etc., in Maple always require parentheses when you are evaluating them at a point: sin(Pi/4), ln(3.4), etc. I'm guessing that when you're pressing return, Maple is putting your cursor back on the spot where it thinks that you are missing a character. It doesn't always get the right spot though.

Good luck exploring Maple. You can usually get help fairly quickly here at MaplePrimes.

## Need to subs x= -x on both input and out...

Use this procedure:

asympt_neg:= (f,x)-> subs(x= -x, asympt(subs(x= -x, f), x, _rest));

A good function to test this on is GAMMA (because GAMMA is not an even function and it has a nontrivial asymptotic series):

asympt_neg(GAMMA(x), x);

You can view the results yourself. You can see that there are a number of differences between this series and the regular asypmtotic series for GAMMA (which is probably the most famous of all nontrivial asymptotic series). If you evaluate this series at, say, -9.5, you'll see that it gives an excellent approximation to GAMMA(-9.5), and a much better approximation than the regular series gives.

## A first step...

(A much-simplified version of what I posted earlier.)

List the positions of all substrings of the given string that match a chemical element symbol.

uses ST= StringTools, ST_PD= StringTools:-PatternDictionary, SC= ScientificConstants;

#PatternDictionary is case sensitive. Thus, all text is uppercased for searching.

local
#Periodic (remember) Table of Elements:
#Map from uppercase elem symbs to standard capitalized symbs.
PTE:= proc(EL::string) option remember; ST:-Capitalize(EL) end proc,

#Dictionary of uppercased elem symbs.
Dict:= ST_PD:-Create(ST:-UpperCase ~ ([SC:-GetElements()])),

#ST_PD:-Search returns seq of 2-member lists, with 2nd member
#being the dict. id# of found pattern. RetStr is operator that turns that id#
#into standard elem symbol.
RetStr:= curry(applyop, curry(PTE@ST_PD:-Get, Dict), 2)
;
export ModuleApply:= (S::string)-> RetStr ~ ([ST_PD:-Search](Dict, ST:-UpperCase(S)));
end module;

Testing it:

[[2, "H"], [1, "Th"], [2, "He"], [5, "C"], [5, "Ca"], [6, "At"], [10, "O"], [9, "Mo"], [13, "Y"]]

So this says that "H" occurs at position 2, "At" at position 6, etc.

For next step, we need to decide what to highlight because there are overlapping choices. For the simple example string above we have 9 matches; it would be quite a mess to highlight them all. Perhaps we should select at random. For the final display, I'm considering doing it as a textplot. That way highlights can be done with color easily under programmatic control

## Data isolation and code flexibility...

Here's a solution.

Marks:= proc(m::And(nonnegative,numeric))
local
k, margin
,CutOffs:= [
[40, "fail"], [50, "third class"], [60, "lower second class"]
,[70, "upper second class"], [100, "first class"]
]
;
for k to nops(CutOffs) - 1 do
margin:= m - CutOffs[k];
if margin < 0 then
return m, cat(CutOffs[k],`if`(margin >= -3, " borderline", ""))
end if
end do;
if m > CutOffs[-1] then
error "invalid input: Argument must be less than or equal to %1 but received %2"
,CutOffs[-1], m
end if;
m, CutOffs[-1]
end proc;

## Continuity of curvature...

I'm guessing that if you're in a math class using space curves, then you've covered the concept of curvature. Is that right? For a smoothly running roller coaster, you'll need continuity of the curves, their derivatives, and their radii of curvature (which are based on the second derivatives). Practically speaking, that means that you need to check that the curves, their derivatives, and their second derivatives match at the splice points.

If you post some of your curves, I'll show you some Maple code to do this. Be sure to include the bounds for the parameters and to indicate where the splice points are.

﻿