Joe Riel

9515 Reputation

23 Badges

18 years, 216 days

MaplePrimes Activity


These are answers submitted by Joe Riel

The way to do this is to compute the compute the intercept point (use yint := (ty*x-y*tx)/(x-tx)) then plot/write that value. I'm not sure what you want to plot it against, maybe just the index? Better would probably be against the distance of the incoming ray from the central axis. Here's how to do that (I added the x_vs_yint table to store the values; using a table, while not necessary here, is more efficient than building a list a term at a time):
with(plots):
with(plottools):
mirror := x -> 8 - sqrt(64 - x^2):     # Mirror
slope := x -> x/sqrt(64 - x^2):        # Slope at each point on mirror
width := 5.0:                          # x = -slope..slope
height := 2 * width:                   # y = 0..height
n := 30:                               # number of light rays

unassign('x'):
unassign('y'):

blk := plot(mirror(x),
            x = -width..width, y = 0..height,
            axes = NONE, scaling = CONSTRAINED, color = black):

rays := {}:
x_vs_yint := table();
cnt := 0;

for i from 0 to n do
    x := -width + 2 * i * width/n:
    y := mirror(x):
    rays := rays union {line([x, height], [x, y])}:   # Incoming ray
    dr := slope(x):
    if (abs(dr) > 0.001) then          # if slope = 0 no outgoing ray
        m := (dr^2 - 1)/(2 * dr):
        ix := (height - y)/m:
        if ix < -width then
            tx := -width:
            ty := y + m * (tx - x):
        elif
        ix > width then
            tx := width:
            ty := y + m * (tx - x):
        else
            ty := height:
            tx := (ty - y)/m + x:
        fi:
        yint := (ty*x-y*tx)/(x-tx);
        cnt := cnt+1;
        x_vs_yint[cnt] := [x,yint];
        rays := rays union {line([x,y], [tx, ty])}:  # outgoing ray
    fi:
od:
rd  := display(rays, color = red, axes = NONE, scaling = CONSTRAINED):
unassign('x'):
unassign('y'):
display({blk, rd});
plot([seq(x_vs_yint[i], i=1..cnt)]);
Do not use with inside a procedure. It is for top-level use only. To access components of a module from a procedure or module, use the use ... end use statement or the uses phrase. You can also give the full path to the command. For example
myproc := proc(s::string)
uses StringTools;
   IsAlpha(s);
end proc:
By default, LinearAlgebra uses, when possible, hardware floats to do Matrix computation of floats. You can explicitly turn this off by setting the environmental variable UseHardwareFloats false.
M := <<0.5|0.5>,<0.3|0.7>>;
                                    [0.5    0.5]
                               M := [          ]
                                    [0.3    0.7]
M^2;
                [0.400000000000000024    0.599999999999999978]
                [                                            ]
                [0.359999999999999986    0.639999999999999904]
UseHardwareFloats := false:
M^2;
                               [0.400    0.600]
                               [              ]
                               [0.360    0.640]
Another possibility is to use the older linalg package, but you need to convert to matrices.
m := convert(M,matrix):
evalm(m^2);
                                [0.40    0.60]
                                [            ]
                                [0.36    0.64]
How about posting a snippet of code that illustrates the problem. You also might want to try using Array rather than array, but its hard to say without seeing what you are doing.
A better approach would be to delete them all in one call.
M := DeleteRow(M, [seq(`if`(M[i,2]=M[i,3],i,NULL), i=1..RowDimension(M))]);
Another way to do this is to keep the rows that are "good".
M := M[[seq(`if`(M[i,2]=M[i,3],NULL,i), i=1..RowDimension(M))], [1..-1]];
To insert a less-than sign in html use &lt;.
A do loop should be no less efficient here:
for i to RowDimension(M) do
   if M[i,2] = M[i,3] then M[i,1] := 0; end if;
end do:
One way is
P := convert(P,units,Torr);
I'm not sure that's what you really want, _C1 is normally considered a constant depending on the initial conditions (which you didn't supply) but you can use solve to solve for _C1:
solve(%, _C1);
y(x)*x-2*x*exp(x)+2*exp(x)-2*x^3
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.
First 107 108 109 110 111 112 113 Page 109 of 114