Joe Riel

9660 Reputation

23 Badges

20 years, 4 days

MaplePrimes Activity


These are replies submitted by Joe Riel

Use < to print the less-than sign in html. Otherwise your input disappears (as you see, or not). You could also change the Input format (below the window you type in) to "Plain Text".
By way of explanation, if you want to insert a backslash in a string, you need to "escape it" by prepending a backslash. Thus,
path := "U:\\acdavid\\MapleFiles"
A single backslash escapes the next character. For most ascii characters the result is the same, however, \a is the BEL character (which rings a bell when printed in a shell). See ?backslash for details. The reason that forward slashes work in this application is that most Windows programs (or the OS) also interpret the forward slash as a directory separator.
By way of explanation, if you want to insert a backslash in a string, you need to "escape it" by prepending a backslash. Thus,
path := "U:\\acdavid\\MapleFiles"
A single backslash escapes the next character. For most ascii characters the result is the same, however, \a is the BEL character (which rings a bell when printed in a shell). See ?backslash for details. The reason that forward slashes work in this application is that most Windows programs (or the OS) also interpret the forward slash as a directory separator.
Assume a vertical ray in the positive direction has angle 0. Then θn, the angle of the normal to the mirror at a point, is given by arctan(dy/dx), where dy/dx is the slope. You've already calculated that. Let the origin of the ray be (0,h). Then the angle of the incident ray to a point (x,y) on the mirror is, using the two argument form of arctan, arctan(x,h-y) (x and y are swapped 'cause we want angle from vertical). From previous expression, compute the angle of the reflected ray and use a big of trig to compute the intersection with the vertical axis.
Assume a vertical ray in the positive direction has angle 0. Then θn, the angle of the normal to the mirror at a point, is given by arctan(dy/dx), where dy/dx is the slope. You've already calculated that. Let the origin of the ray be (0,h). Then the angle of the incident ray to a point (x,y) on the mirror is, using the two argument form of arctan, arctan(x,h-y) (x and y are swapped 'cause we want angle from vertical). From previous expression, compute the angle of the reflected ray and use a big of trig to compute the intersection with the vertical axis.
Let θ be the angle of any line (from some arbitrary reference line, usually the horizontal or vertical). Then if θn is the angle of the normal to the mirror at a point, and θi is the angle of an incoming ray, then θo = 2θn - θi is the angle of the outgoing ray.
Let θ be the angle of any line (from some arbitrary reference line, usually the horizontal or vertical). Then if θn is the angle of the normal to the mirror at a point, and θi is the angle of an incoming ray, then θo = 2θn - θi is the angle of the outgoing ray.
To save a bit of typing you could also do
eval(eq1, tan=sin/cos)
To save a bit of typing you could also do
eval(eq1, tan=sin/cos)
To add a comment to the main thread, scroll down farther on the page and fill in the response box in the "Post New Comment" section. Don't click "reply" (which I'm doing, since I'm replying to your comment).
To add a comment to the main thread, scroll down farther on the page and fill in the response box in the "Post New Comment" section. Don't click "reply" (which I'm doing, since I'm replying to your comment).
Agreed. My post was unclear, I meant that it had no effect on this particular code. There was no implication that it always has no effect.
Agreed. My post was unclear, I meant that it had no effect on this particular code. There was no implication that it always has no effect.
I don't understand your complaint. If you call the procedure more than once, the printed result (time of execution) will be incorrect, since stx is not reset with each call (nor is restart called, it cannot be from inside a procedure). If you want to time this procedure, do
time(test2(10000,10));
                           40.419
Note that essentially all the performance gain of picks[0.1] is achieved when the datatype=float[8] option is provided. Without it, picks[0.1] runs at the same speed as picks[0.65] (the map trick with unevaluated rnd(3)). While trying other improvements I stumbled across this "gem"
picks[0] := proc(n::posint)
local opacity,rnd;
    opacity := kernelopts('opaquemodules'=false);
    rnd := RandomTools:-MersenneTwister:-MTKernelInterface;
    kernelopts('opaquemodules'=opacity);
    eval(Array(1..n,1..2,'fill=rnd(3)'));
end proc:
It was four times faster than picks[0.1]! Then I discovered a tragic flow:
 A := picks[0](2);
                   [0.849129305868777108    0.678735154857773470]
              A := [                                            ]
                   [0.743132468124916179    0.655477890177556644]

A[1,1] <> A[1,1];
                  0.171186687811561766 <> 0.706046088019608775
It's clear now what the problem is, but I found it amusing.
First 176 177 178 179 180 181 182 Last Page 178 of 195