Joe Riel

9530 Reputation

23 Badges

20 years, 24 days

MaplePrimes Activity


These are answers submitted by Joe Riel

You can also use the Bernoulli distribution for this

with(Statistics):
X := Bernoulli(0.495):
Mean(X);
                  0.495
Sample(X,10);
                 

Student[LinearAlgebra][RotationMatrix]

 

ThU's response is correct.  Here is a bit more detail. Click the Plots tab in the right-pane. Click the combo-box and select "add plot"; enter a plot name in the pop-up window (that identifies it if you later have to edit the settings).  After that you should see a text area region with "Empty" in it. Click it and some more stuff will appear. In the x-axis combo-box select the probe you want for the x-axis. In the y-axis combo-box select the probe for the y-axis (you can add multiple probes by clicking Add Variable). When complete, run the simulation and you should see a second plot.

One approach is the following. It uses a loop to generate one solution at a time, then uses the 'avoid' option of fsolve to prevent solving for the same root twice. 

y := exp(x)*cos(x)+1=0:

all := NULL:
do
   sol := fsolve(y,{x=0..10},'avoid'={all});
    if not sol :: set then
        break;
    else
        all := (all,sol);
    end if;
end do:

all;

Besides the syntax issues pointed out by nm, there is a more fundamental issue.  Division should be avoided because the denominator could go to zero.  A better approach is to compute the wedge product of two vectors corresponding to the two lines, if it is non-zero then they are not parallel. This is nice in that it also works in n-dimensions. The vector corresponding to a line is just the difference between two points on the line. In two dimensions, the wedge product of vectors [x1,y1] and [x2,y2] is x1*y2 - x2*y1. Note that this test fails if one or both of the vectors is 0.  That would happen if the two points that designated a line were not distinct.

The requirement that the area go to zero if a segment intersects  is curious.  Ignoring that for the nonce, a simple method is to compute the signed-area.  Assume P is a listlist of points, with P[1] = P[-1], then

SignedArea := proc(P)
 local i,n;
   if P[1] <> P[-1] then
        error "first and last points must be identical";
   end if;
   n := numelems(P);
   1/2*add(P[i][1]*P[i+1][2]-P[i+1][1]*P[i][2], i=1..n-1);
end proc:

I don't see much hope in doing this for a symbolic n, but it easy enough to do if n is given a value.

f := proc(x)
local n;
    # get the index of the calling procedure
    n := op(procname);
    if n :: posint then
        if n = 1 then
            x;
        else
            x + sin(f[n-1](x));
        end if;
    else
        'procname'(x);
    end if;
end proc:

f[3](x);
                              x + sin(x + sin(x))

diff(f[3](x),x);                       1 + cos(x + sin(x)) (1 + cos(x))

 

Another possibility is to use ?depends instead of ?has.  It tests whether the expression depends, mathematically, on name or names. For example

select(depends, Int(x, x=0..1) + x, x);
                                                                x

The integral uses (has) x, but does not depend on it as it is a dummy variable.

The directories in the path to the file must exist. So you could do

dir := "/tmp/whatever1/whatever2":
if not FileTools:-IsDirectory(dir) then
    FileTools:-MakeDirectory(dir, 'recurse');
end if;
mla := cat(dir, "/mymla.mla"):
march("create", mla);

?LibraryTools:-SaveLib is different from ?savelib, the latter is a lower level command. Use the former, instead.

The constraint x^2 + y^2 <= 2*y is equivalent to x^2 + (y-1)^2 <= 1, which is the interior of a unit circle with center at (0,1).  The area of interest is the portion below the line x=y.  In polar coordinates, the two-form being integrated is r^2*dr &^ dtheta.  Let omega = 1/3*r^3*dtheta, so d(omega) = r^2*dr&^dtheta.  Using Stokes' theorem, integrate omega along the boundary of the region.  The integral is zero on the straight part because the flow is orthogonal to the path, so we just have to integrate the curved section.  Along the curve, r = 2*sin(theta), so we get

8/3*int(sin(theta)^3, theta = 0..Pi/4) = (16 - 10*sqrt(2))/9

which agrees with Preben's result. 

To achieve that, do

plotsetup(char):

To restore the normal plot, do

plotsetup(default):

 

Could you demonstrate what you mean by running j from  1 to s separately?

The following hint might be useful. Rather than assign to to a table a, make a a matrix.  That is, before the double loop, assign

a := Matrix(s):

then at the conclusion of the double loop, display a:

a;

That makes it easier to visually check whether it is what you expect.

 

 

 

Try posting just text, or a worksheet with input.  You've trimmed all the useful input, that worksheet is not usable as is.

You could try something like the following:

y := 1 + a/c + b/c^2:
subs(c=1/cinv, y):
subs(cinv=1/c, convert(series(%, cinv, 2),polynom));
                                                        1 + a/c 

As Acer recommends, the immediate code behind an embedded component should be short. I restrict it to a single procedure call, possibly with an argument appropriate to the particular component. During the development, I use the form

(SomeAction)();

Then, when I need to debug this, it can be quickly instrumented by changing it to

mdc(SomeAction)();

that is, by prepending mdc to the function call.  The mdc procedure---the main entry point to the Maple Debugger Client---instruments its argument and returns the procedure, which is then executed and launches a nice debugger. Contact me if interested in mdc. 

Use

kernelopts(printbytes=false):

 

First 31 32 33 34 35 36 37 Last Page 33 of 114