Joe Riel

9660 Reputation

23 Badges

20 years, 3 days

MaplePrimes Activity


These are answers submitted by Joe Riel

Create a Random Data template, select the desired distribution (Gaussian), fill in the parameters, select the number of points and simulation time, then click the Generate Random Data button.  That attaches a worksheet to your document with the data.  To use, insert a Time Lookup Table block (Signal Blocks --> Interpolation Tables --> Time Lookup and connect the output signal to whatever is desired.

I assume you meant a Time Lookup table.  Use the same data (spreadsheet or csv file) in a 1D interpolation table and connect its input to a sawtooth generator ( Signal Blocks --> Sources --> Real --> Saw Tooth ), with amplitude = T = 20.

What frequently works is to use Ctrl-/, which returns the cursor to the baseline.  You won't want to do that if you are inserting a superscript in an expression that is not on the baseline.  The advantage of Ctrl-/ is that it can be typed without leaving the home row (at least if you've configured your keyboard to make the Ctrl key readily accessible).

I wish that there were another binding for the right-arrow function that uses a more convenient key.

One way (not ideal, but easy to enter)

N := 15:
L := LinearAlgebra[RandomVector](N):

member(min(L),L,'i');
i;

A ZOH block takes two parameter, the sampling interval and the start of the samplilng.  The sampling interval is fixed by your discrete system, it should match that.

Why not use the triggered sampler (in Signal Blocks -> Discrete).

 

The `and` should not be in there.  Is that supposed to be an algebraic constraint?  If so then the system is over-determined.

?plots[odeplot] can handle this.

S:=0.79*cos(t)+0.3*sin(t);
DGL1 := 20*(D(D(x)))(t)+10*(D(x))(t)+2500*x(t)+300 = S;
init := x(1.2) = 0, (D(x))(1.2) = 10.63081252;
F := dsolve({DGL1, init}, numeric):

plots:-odeplot(F, [t,x(t)-S], 1.2 .. 2, 'numpoints'=200);

?NLPSolve doesn't handle symbolic parameters. The variable a must be assigned a numeric value.

Here's an example of computing the minimum velocity of thrown object

deqs := { NULL
          , vx(t) = diff(x(t),t)
          , vy(t) = diff(y(t),t)
          , diff(vx(t),t) = 0
          , diff(vy(t),t) = -1
        }:

ini := { NULL
         , x(0) = 0
         , y(0) = 0
         , vx(0) = 1
         , vy(0) = 1
       }:

proceqs := dsolve(deqs union ini, 'numeric', 'output=listprocedure' ):

Vx := eval(vx(t), proceqs):
Vy := eval(vy(t), proceqs):

V := t -> sqrt(Vx(t)^2+Vy(t)^2):

Optimization:-Minimize(V, 0..2);
[1.00000000000000, [0.999999968364665]]

The problem is that the solution contains symbolic F (F[4]), so you cannot assign the result to F.  For example

F := F[4];
Error, recursive assignment

Just change the lhs

dsol := dsolve(...);

Here's the routine I'd use. It uses some low-level Maple operations to make this reasonably efficient, those might not be suitable for the course you are taking (it sounds like a general programming course).

MergeSort := proc(L1::list, L2::list)
local i,i1,i2,n1,n2,V;

    # Handle empty lists
    if   L1 = [] then return L2;
    elif L2 = [] then return L1;
    end if;
    # Neither list is empty, so we do the merge.
    n1 := numelems(L1);
    n2 := numelems(L2);

    # Allocate Vector to store merged items
    V := Vector(n1+n2);

    # Initialize indices used for L1 and L2.
    i1 := 1;
    i2 := 1;

    # i is the index used for V
    for i to n1+n2 do
        if L1[i1] < L2[i2] then
            V[i] := L1[i1];  # move smaller item to V
            i1 := i1+1;      # increment i1
            # check whether there are more items in L1
            if i1 > n1 then
                # L1 is empty, so the rest comes from L2.
                return [seq(V[i], i=1..i), op(i2..,L2)];
            end if;
        else
            V[i] := L2[i2];
            i2 := i2+1;
            if i2 > n2 then
                # L2 is empty, so the rest comes from L1.
                return [seq(V[i], i=1..i), op(i1..,L1)];
            end if;
        end if;
    end do;
end proc:

Here is the basic idea

MyMod := module()
option package;
export A,B;
   (* assign A and B *)
end module:
LibraryTools:-Save(MyMod, "somewhere/mylib.mla"):

If the directory to "somewhere" is in ?libname, Maple will then find the mla and load it when you do with(MyMod).

To assign libname, you do so in an initialization file. You could, instead, use an explicit assignment in each worksheet you open, but that quickly becomes a pain.  To avoid dealing with the initialization file, you could put the library in a place where Maple should be looking anyway.  The following should work (I use a linux system, so those with Windows may need to tweak this, though forward slashes usually work).

dir := sprintf("%s/maple/toolbox/MyStuff/lib", kernelopts('homedir'));
FileTools:-MakeDirectory(dir, 'recurse');
file := sprintf("%s/MyMod.mla", dir);
LibraryTools:-Save(MyMod, file);

The procedure getListSize is about the worst way to get the size of a list.  Try using ?numelems (or ?nops).

Since this is an assignment, I'm reluctant to just post a solution, but will help if you post some progress. The basic algorithm of a merge sort is pretty straightforward. Keep three indices, one for the output and one for each input list. Compare the associated input list elements, pick the smaller (assuming you are sorting from smallest to largest), move it to output, increment the selected input index and output index.  When one list runs out of items, you can then move the rest of the other list to the output.  Use a Vector for the output structure (you know its size), then convert to a list when done. Before starting the comparison loop, check whether either input list is empty, if so, just send the other to the ouput.

Consider factoring the exponent and solving for those polynomials.

p := 2017*x^2013+2015*y^2013-2033*z^2013-2011:

e := 2013:
F := map2(op,1,ifactors(e)[2]);
                          F := [3, 11, 61]

isolve(subs(e=F[1], p));
isolve(subs(e=F[2], p));
isolve(subs(e=F[3], p));

isolve returns NULL for each.  That doesn't mean there necessarily isn't a solution...

First 40 41 42 43 44 45 46 Last Page 42 of 114