Robert Israel

6577 Reputation

21 Badges

18 years, 209 days
University of British Columbia
Associate Professor Emeritus
North York, Ontario, Canada

MaplePrimes Activity


These are answers submitted by Robert Israel

It might help if you posted some actual code, but what might be happening is something like this.
> assume(x > 0);
  y:= x + 1;
  subs(x=3, y);
4
> save y, "foo.m";
  restart;
  read "foo.m";
  subs(x=3, y);
x~ + 1 What is happening here? When an assumption is made on a variable x, Maple produces a new variable (which, depending on your settings, may or may not be shown as x~), and assigns it as the value of x. So y is assigned the value x~+1, and then subs(x=3, y), actually substitutes x~=3 into that, producing 4. When I produced the file "foo.m", I saved the value of y, but not the value of x. So after the restart Maple reads y:= x~ + 1 from the file, but there's no connection between x~ and x, and the subs command makes no changes. It would be somewhat better if we had saved the values of both x and y, i.e.
> save x, y, "foo.txt";
However, although that would solve the subs problem in this case, it's not really a satisfactory solution, because the assumption of x > 0 is still not saved.
Perhaps there are two points to make here. 1) Maple does its computations in a ring of rational functions, where it's legitimate to make simplifications such as x/x -> 1. But this would not be valid for x = 0. Thus it's quite easy to have situations where computing f(x) and then substituting x=0 succeeds, while computing f(0) directly fails. 2) The body of a procedure is not evaluated when it is defined. Thus
simpleftilde:=(x,lambda)->simplify(ftilde(x,lambda));
means that simpleftilde(x,0) will first compute ftilde(x,0) and then (if there is no error) simplify the result. If you wanted it to evaluate the result of simplifying ftilde(x,lambda) at lambda = 0, you could have said
> simpleftilde:= unapply(simplify(ftilde(x,lambda)),(x,lambda));
Unfortunately, Maple is not so consistent. The variables that stand for an integer are _Z1, _Z2, etc. (which, depending on your settings, you may see as _Z1~, _Z2~ etc). _Z is generally found in a RootOf, where it is just an ordinary variable that has no assumptions on it. Thus RootOf(_Z^6 + 7*_Z + 1) means any solution _Z of the equation _Z^6 + 7*_Z + 1; RootOf(_Z^6 + 7*_Z + 1, index = 1) to RootOf(_Z^6 + 7*_Z + 1, index = 6) are particular solutions (in whichever order Maple puts those roots).
The main problem, I think, is that you have neglected to put a space (or *) between the b and the x. Maple thinks bx is a single variable unrelated to b and x. I assume the square brackets around a/x are not really there, because they would mess things up and you wouldn't even get 1 (square brackets make a list, and you don't want that here).
Not as such, but shouldn't be too hard to write a simple RPN interpreter in Maple. You might want to use a Maplet to get the input as a string and pass it to the interpreter. This version allows only a few mathematical functions that take a single input (the list could be expanded, but functions that can take varying numbers of inputs would be impossible for RPN to handle), and assumes tokens in the input are separated by whitespace.
> RPNfns:= ["sin", "cos", "tan", "ln", "exp", "sqrt"]:
  RPNops:= ["+","-","*","/","^","mod"]:
  RPNInterpreter:= proc(s::string)
   local a,st, r1, r2, d;
   st:= stack[new]();
   for a in StringTools[Split](s) do
     if a = ":=" then
       r2:= stack[pop](st);
       r1:= stack[pop](st);
       assign(r1,r2)
     elif member(a, RPNops) then
       r2:= stack[pop](st);
       r1:= stack[pop](st);
       stack[push](eval(convert(a,name)(r1,r2)),st);
     elif member(a, RPNfns) then
       stack[push](eval(convert(a,name)(stack[pop](st))),st);
     else stack[push](op(sscanf(a,"%a")),st)
     fi
   end do;
   if stack[depth](st) <> 1 then 
     error "%1 items left on stack", stack[depth](st)
   end if;
   eval(stack[pop](st))
 end proc;
For example:
> RPNInterpreter("3 c 2 * mod 1 sin +" );
`mod`(3,2*c)+sin(1) And now to put it in a Maplet:
> doit:= proc() 
    RPNInterpreter(Maplets[Examples][GetInput](
    "Enter RPN:", title="RPN Input"))
  end proc:
  doit();
> select(hastype, k, sqrt);
The worksheet was not attached. Please edit your posting to include the link.
The first sum does not seem to converge. As n -> -infinity the even and odd summands seem to approach 1 and -1 respectively (although asympt and limit don't give me any results). Maple uses a summability technique to get the result for a. If you set _EnvFormal := false, you get Float(undefined) for a.
Maple doesn't have a sinc function. If you mean the function sinc(x) = sin(x)/x, you could say something like
> eval(expr, {sin = (x -> x*sinc(x)), 
              cos = (x -> (x+Pi/2)*sinc(x+Pi/2)),
              tan = (x -> x*sinc(x)/(x+Pi/2)/sinc(x+Pi/2))});
No, I don't think so. A Plotter doesn't even have an "onclick" option like a Button has, or any equivalent of that, so AFAIK there's no way for it to determine that anything has been dropped on it. I suppose something might be done with Java and OpenMaple, but as I understand it that would be mainly a matter of Java programming more than Maple programming: you'd have to write your own Java equivalent of a Plotter, and get it to render curves that you might get as Maple plot structures from calling the Maple engine.
I suspect that getting Maple to format your equations correctly would be such a time-consuming activity that it would be very difficult to keep up with most math lecturers. The distraction of trying to do this would almost certainly make it impossible to understand the lecture as it is given. It's much better, I think, to take hand-written notes; if you want to transcribe them into Maple later, then do so. Or if you find this difficult, you might record the lectures on a video camera (better get the instructor's permission before doing this).
Actually, that doesn't work. The help page for ?save says
Each argument except the last one is "evaluated to a name", while the last argument (the file name) is fully evaluated.
In your example
> nm := anames('user');
> save nm, savtry11;
the only variable whose value will be saved is nm: the contents of the file savtry11 will be
nm := y, x, a;
and the values of y, x and a are not saved. That remark about evaluation to a name is also the reason why
> save(anames('user'), savtry9);
doesn't work: save doesn't evaluate its argument anames('user'). A work-around is this:
> parse(sprintf("save %q", anames('user'), savtry12), 
     statement);  
If t is not an integer, you can't "parse" it to an integer. I assume that t will be a real number, and you want to round it to the nearest integer. So you can use
round(t)
f(x) = sin(x) + sin(2*x) = sin(x) (1 + 2 cos(x)) has period 2*Pi. It attains its maximum at x = x0 + 2*Pi*n for integers n, where x0 = arcsin(1/8*(30+2*33^(1/2))^(1/2)). sin(Pi*x) has period 1, and its maximum is attained at x = 1/2 + 2*m for integers m. Since Pi is irrational, f(x) is not periodic. It has no global maximum, but comes arbitrarily close to its supremum at points that are simultaneously close to x0 + 2*Pi*n and 1/2 + 2*m for integers m and n, i.e. c = x0/2 - 1/4 is approximately m - Pi*n (assuming we can't have c = m - Pi*n). By a theorem of Minkowski, there are infinitely many pairs (m,n) such that abs(c-(m-Pi*n)) < 1/(4*abs(n)). One of these is (m=-160,n=-51) where 1/2 + 2*m = -319.5 and x0+2*Pi*n = -319.5065..., so f(x) has a near-maximum near x = -319.5. By symmetry, it has a near-minimum near x = 319.5.
What do you know about the determinant of the product of two square matrices?
First 122 123 124 125 126 127 128 Last Page 124 of 138