Joe Riel

9630 Reputation

23 Badges

19 years, 246 days

MaplePrimes Activity


These are answers submitted by Joe Riel

Edited after posting. Modified procedure to permit strings as indices. What you want is doable, at least using the Maple 10 Standard gui, however, it requires the use of some undocumented procedures in the Typesetting package. My knowledge of these is scanty. The following seems to do what you desire. By default it inserts an extra space following the comma that separates items. If you pass a nonnegint as an index to the procedure, it will use that number of spaces. If you pass a string as the index, it will insert that string between each element.
PrintExtraSpace := proc()
local a, spaces;
uses Typesetting, ListTools;
description "print arguments with extra space following commas";
    if not IsWorksheetInterface('Standard') then
        return args;
    end if;
    if procname::indexed then
        spaces := op(procname);
        if [spaces]::[nonnegint] then
            spaces := cat(",", " "$spaces);
        elif not [spaces]::[string] then
            error "index to procedure must be a nonnegative integer or a string";
        end if;
    else
        spaces := ",  ";
    end if;
    mrow(JoinSequence([seq(Typeset(EV(a)), a in args)]
                      , mi(spaces))[]);
end proc:
For two spaces do
PrintExtraSpace( ... );
For more space do
PrintExtraSpace[5]( ... );
If you want some other separator, including the comma, insert it as a string in the index
PrintExtraSpace[";---"]( ... )
Note that you won't be able to usefully copy and paste the output. If you compare this output to the standard output, you'll notice that the inserted comma is bolder.
The LinearAlgebra package uses Matrices and Vectors, not matrices and vectors. They are different beasts. The linalg package, on the other hand, uses matrices and vectors, not Matrices and Vectors. Matrices and Vectors are a newer Maple construct. In your example you could do
with(LinearAlgebra):
A:= Matrix(3,3,[$1..9]);
ScalarMultiply(A,3);
You could also do
A . 3;
or
3 . A;
or even
3*A;
Yes, it is possible. In 2D mode type Delta, Ctrl-Shift-Space x. The 'Ctrl-Shift-Space' sequence is for the linux OS, I'm not sure about Windows. Check the Help->Quick Reference "2D Math Editing Operations, Keyboard Shortcuts and Operations" (last line in that subsection).
The frontend command can be wielded with nice effect here,
frontend(LinearAlgebra:-Eigenvectors, [A(p)], [{Matrix},{}]);

                               [a2(p)]  [0    1]
                               [     ], [      ]
                               [a1(p)]  [1    0]
If the jpeg is not a color image, then the resulting image can be converted to a Matrix (a color image cannot be converted to a Matrix because it requires at least 3 layers). One way is to use the Create command in ImageTools:
with(ImageTools);
img := Read("your_picture.jpg"):
img := Create(img,format=Matrix,copy=true);
It is necessary to specify the format and copy options. Were you planning on directly multiplying the image and the filter matrix? There is a Convolution procedure that convolves an image with an rtable (Matrix or Array). You can use the View command (in ImageTools) to view the result. Here is a simple example:
img := Checkerboard():
View([img,Convolution(img, <<1|0|0|1>>)]);
That displays a side-by-side view of the original image and the convolved image.
Maple's invlaplace function does not know how to compute the inverse laplace of exp(-td*s). We can, however, use the addtable function to add an entry to the transform table. Alas, this doesn't work as well as it could. That is, we cannot replace Maple's partial knowledge about the inverse laplace of exp. Instead, use a new function name, say, Exp to represent the exponential. Then we can do
with(inttrans):
addtable(invlaplace, Exp(-k*s), Dirac(t-k), s, t, [k]):
H1 := s -> 1/s:
D1 := s -> (Exp(-td*s) - Exp(-s))/s:
T1 := s- > D1(s)*(H1(s)):
invlaplace(T1(s),s,t);
    (-Heaviside(-t + td) + Heaviside(td)) (t - td) - Heaviside(t - 1) (t - 1)
What you want to do is to combine the left and right sides of the equations into a single polynomial in terms of u and v, extract all the coefficients, equate them to zero, and solve for the parameters. This can be done in one line:
solve({coeffs((lhs-rhs)(eq1), {u,v})});
             {a3 = 0, a6 = 0, a4 = -3, a1 = 5, a2 = -5, a5 = 7}
However, more instructive is to do this one step at a time:
p := (lhs-rhs)(eq1);
        2                             2                                     2      
    a1 u  + (a4 + 3 + 2 a6) u v + a3 v  + (a1 + a2 + a6) u + a5 v + a6 - 5 u  - 7 v

p := collect(p, {u,v});
               2                                              2                  
    (-5 + a1) u  + ((a4 + 3 + 2 a6) v + a1 + a2 + a6) u + a3 v  + (a5 - 7) v + a6

eqs := {coeffs(p, {u,v})};
           {a1 + a2 + a6, a4 + 3 + 2 a6, a3, a6, -5 + a1, a5 - 7}

solve(eqs);

             {a3 = 0, a6 = 0, a4 = -3, a1 = 5, a2 = -5, a5 = 7}
Note the use of collect, which was omitted in the one-liner. While this isn't necessary for this example, in general it is required for coeffs to correctly compute the coefficients of the polynomial. A one argument call to solve was used because all the indeterminates of the set of expressions passed to solve were the unknowns to solve for.
simplify(Ans,symbolic), though possibly a bit heavy-handed (see ?simplify,details), works here to cancel the desired terms (as well as combine the 1/x and x terms outside the Sum).
The problem is that Maple is attempting to solve a polynomial with 365 terms. A better approach would be to solve this symbolically:
eq := (1 + j/n)^m = val:
sol := solve(eq, j);
                      sol := exp(ln(val)/m)*n-n
eval(sol, [n = 365, m = 365, val=1.1]);
                                   0.0953227
True, but that only works if the scaling factor is a nonzero numeric.
The easy way to handle this is to input the expression as a piecewise expression then use convert/Heaviside to convert it to an expression with unit steps (Heaviside functions). Finally use inttrans[laplace] to find its Laplace transform:
f1 := piecewise(t <= 1, 0, t<=4, cos(Pi*t), 0):
f2 := convert(f1,Heaviside);
              f2 := cos(Pi t) Heaviside(-1 + t) - cos(Pi t) Heaviside(-4 + t)
inttrans[laplace](f2, t, s);
                    -s*(exp(-s)+exp(-4*s))/(s^2+Pi^2)
To input a less-than sign (<), use the html construct &lt; (the semicolon is necessary).
There shouldn't be any problem pasting multiple lines, the real issue, I suspect, is that Maple won't accept the 2D output as input. A simple way to workaround that is to use lprint (or set interface(prettyprint=1)). The output of lprint is in 1D notation, which can be pasted into an input line. If you do not want any line breaks in the output, call interface(screenwidth=infinity) before issuing lprint. You don't normally want screenwidth = infinity because it breaks Maple's normal output (which trys to center on the screenwidth). That isn't an issue with lprint, since it prints flush left. You can write a simple procedure to temporarily reassign screenwidth and print the expression in 1D format, flush left: Lprint := proc() local width; width := interface('screenwidth' = infinity); lprint(args); interface('screenwidth' = width); NULL end proc:
This is a classic case of premature evaluation. In the plot3d statement, the expression Shape(x,y) is evaluated as is, that is, with the symbolic constants x and y as arguments to Shape. Because their values are themselves, Maple cannot evaluate the conditional. There are a few ways to handle this. The simplest might be to just pass the procedure Shape to plot3d: plot3d(Shape, -100..100, -100); Note that the x and y ranges are passed as ranges, not as equations. Another possibility is to modify Shape to return an unevaluated function call to Shape when x and y are not numeric: Shape := proc(x,y) if x::numeric and y::numeric then `if`(x^2 + y^2 < (Diameter/2)^2, 1, 0); else 'Shape'(args); end if; end proc: A somewhat more robust approach would also check whether Diameter is numeric.
I'm unclear on what you are asking. Do you want the unevaluated function call myproc(x,y) to display as `x whatever y'? You can more or less accomplish that by creating a `print/myproc` procedure and using a neutral operator (see ?print and ?neutral for details).
`print/myproc` := proc(a,b) a &whatever b end proc:
myproc(a,b);
                  a &whatever b
Try using combine/power: y := 12/b/(b^s)*s/sin(Pi*b)^2*Pi^2; combine(y, power); 12/b^(s+1)*s/sin(Pi*b)^2*Pi^2
First 108 109 110 111 112 113 114 Page 110 of 114