Carl Love

Carl Love

28050 Reputation

25 Badges

12 years, 349 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

If you expand the expressions "by hand", you will see that all the t's cancel.

t*x + (1-t)*x = t*x + x - t*x = x.

I will give an example of inputting a piecewise function, but I don't know what you mean by "solve a piecewise function". The general pattern is

piecewise(cond1, piece1, cond2, piece2, ..., condN, pieceN, piece_otherwise);

where cond1, ..., condN are Boolean expressions (typically simple inequalities in one variable), and piece1, ..., pieceN, and piece_otherwise are algebraic expressions (typically with the same variable being considered the independent variable).

Example:

f:= piecewise(x < 0, x^2, x < 1, x+1/2, x < 2, 1, 1.25);
plot(f, x= -1..3, discont, symbol= solidcircle, symbolsize= 15);

Note that at each condition, going left to right in the command, it is assumed that the conditions to the left have already been rejected, so the second condition in the example can be simply x < 1; there's no need to make it a compound condition such as 0 <= x and x < 1. (If you must enter compound conditions, see ?piecewise for details on the inert form required.)

Once you have f input, you can use it like any other algebraic expression in Maple: You can incorporate it into a more-complicated expression, and you can apply commands such as solve, diff, int, limit etc., and, to a limited extent, dsolve.

Assign the solution from QPSolve to a variable. For example,

Sol:= QPSolve(...);

Now, whenever you want one of the variables from Sol, use eval(... , Sol[2]); For example,

x1:= eval(x1, Sol[2]);

or

eval(y, Sol[2]) + eval(z, Sol[2]);

Just place a list of 6 colors in the cuboid command:

rand256:= rand(0..255):
RandColor:= ()-> COLOR(RGB, evalf(['rand256()/256' $ 3])[]):
C:= plottools:-cuboid([0$3], [1$3], color= ['RandColor'() $ 6]):
plots:-display(C, transparency= 0.5, axes= none);

In your eq16 you missed transcribing the leading minus sign from eq15.

Continuing from that point, you should have

eq16:= subs(C= -hmax*ln(-hmax), eq13);
eq17:= solve(eq16, h);

#Include initial condition in dsolve solution.
eq11_1:= dsolve({eq10, h(0)=0}, implicit);
eq12_1:= solve(eq11_1, h(t));

simplify(eq12_1 - eq17);

And you should get 0 (I did) indicating that the two methods are equivalent.

@esbestan 

M is a matrix that you can work with. But the interface, by default, does not display large matrices, even though the matrix still exists in the computer's memory. You can change the default behavior with the command

interface(rtablesize= infinity);
M;

and you will see all of M. You can also view submatrices. For example, to see the 1st through 10th rows and the 10th through 20th columns,

M[1..10, 10..20];

Well, obviously, you can't just use ... and expect Maple to figure out the pattern; you have to use seq. But there is a problem with using the seq with the vertical bars | ... |. To get around this, we use the vertical bar Matrix constructor in prefix form, `<|>`(...), like this:

restart:
m:= 32:
for i from 0 to m-1 do  h[i]:= unapply(t^i)  end do:
H:= unapply(< seq(h[i](t), i= 0..m-1) >, t):
M:= `<|>`(seq(H(i/m), i= 0..m-1));

Erik,

Here's a complete example of using the recursive procedure and generating the output with evalhf. I used the sum-of-squares for the first real-valued evaluation function, and the sum-of-cubes for the second.

Combi:= module()
export
    boxContent,  #A vector whose i'th entry holds the number of marbles in the i'th box
    Output       #Matrix of Output value
;
local
    Combi:= proc(
        k::integer, Combi:= module()
        boxContent::Vector,
        activeBox::integer,
        marblesRemaining::integer,
        Output::Matrix,
        Index::Vector
    )       
    local i::integer;
        
        if activeBox < k then
            for i from 0 to marblesRemaining do
                boxContent[activeBox]:= i;
                thisproc(k, boxContent, activeBox+1, marblesRemaining-i, Output, Index)
            end do
        else
            boxContent[activeBox]:= marblesRemaining;
            Index[1]:= Index[1] + 1;
            #Something:
            Output[1, Index[1]]:= add(boxContent[i]^2, i= 1..k);
            Output[2, Index[1]]:= add(boxContent[i]^3, i= 1..k);        
        end if;
    end proc,

    ModuleApply:= proc(n::posint, k::posint)
    local
        Index,
        boxContent  #A vector whose i'th entry holds the number of marbles in the i'th box
    ;
        boxContent:= Vector(k, datatype= float[8]);
        Output:= Matrix(2, binomial(n+k-1, k-1), datatype= float[8]);
        Index:= Vector(1);
        evalhf(Combi(k, boxContent, 1, n, Output, Index));
        [][]
    end proc
;
end module;

And the worksheet:


A recursive procedure

restart

with(Statistics):

n := 40:

k := 6:

 

module () local Combi, ModuleApply; export boxContent, Output; end module

NULL

B := CodeTools[Usage](Combi(n, k));

memory used=18.65MiB, alloc change=18.64MiB, cpu time=3.45s, real time=3.45s

Combi:-Output[1, 1221759];

HFloat(1600.0)

Combi:-Output[2, 1221759];

HFloat(64000.0)

``


Download A_recursive_procedu.mw

From your worksheet, I think that you've already noticed that this is a bug related to the strange way that you created V, which is equivalent to this shortened form:

restart:
v1:= <a>: v2:= <b>:
V:= Vector(2, [v1,v2]):
subs(a=5, V);

The workaround is to create V like this:

V:= <v1,v2>:
subs(a=5, V);

RootPlot:= (p::polynom)->
     plot(map([Re,Im], [fsolve](p, indets(p,name)[], complex)), style= point,  _rest):

RootPlot(1+randpoly(x, degree= 2^7), color= green, symbol= diamond);

The command StringTools:-ParseTime (see ?StringTools,ParseTime ) can be used on the timestamps, like this (ignoring the time zone):

restart:
timestamp:= "2013-08-13T00:29:24+0000": #Note the quotes
timerecord:= StringTools:-ParseTime("%Y-%m-%dT%T", timestamp):

This produces a structure called a ?Record which holds then numeric values for year, month, etc.

baseyear:= 2012:  basemonth:= 9:  #For example
CountMonths:= TR-> 12*(TR:-year - baseyear) + TR:-month - basemonth:
CountMonths(timerecord);
                               11
Now this gives you a way to measure distance on the horizontal axis.

The command ListTools:-Classify can be used to count the photos, texts, etc., for each month (see ?ListTools,Classify ).

See ?plot,tickmarks for information about changing the tickmarks on the horizontal axis.

See ?plots,polygonplot to plot the colored rectangles.

 

The problem is that you did not declare an Array, so gg became a table. But, gg cannot be a Vector (or a list) because it is indexed from 0 instead of 1. It has to be an Array or a table.

You can create an Array and fill it in one step:

gg:= Array(0..7, i-> t-> t^i):

If you want to apply all the functions in gg at once, you can do this (I am using 2 as the argument):

gg2:= map(`?()`, gg, [2]);

gg2[5];
                          32

S:= {[-2, 1, 1, -2, 1, 1], [-2, 1, 1, 2, -1, -1], [0, -1, 1, 0, 1, -1], [0, 1, -1, 0, -1, 1]}:

Vectors u and v are multiples iff (u.v)*u = (u.u)*v. Proof of this is left as an exercise.

IsMultiple:= (u::~Vector, v::~Vector)-> ArrayTools:-IsZero(u.v*u - u.u*v):

If we exclude the zero vector, which is a multiple of everything, IsMultiple is an equivalence relation on the remaining vectors. ListTools:-Categorize will partition a list into equivalence classes.

S1:= S minus {[0$nops(S[1])]};   
L:= ListTools:-Categorize(IsMultiple, [S1[]]);
       [[-2, 1, 1, -2, 1, 1]], [[-2, 1, 1, 2, -1, -1]],
         [[0, -1, 1, 0, 1, -1], [0, 1, -1, 0, -1, 1]]

Select a representative (the first element) of each equivalence class.

map(`?[]`, {L}, [1]);
{[-2, 1, 1, -2, 1, 1], [-2, 1, 1, 2, -1, -1], [0, -1, 1, 0, 1, -1]}

The answer is, briefly, no, Maple cannot work with matrices and vectors of arbitrary, symbolic dimension. (Considering the number of questions that I see about it here, this could be one of the next frontiers for symbolic computation.) If you can deduce (with mindpower) a recurrence along a single dimension, you might be able to solve it with rsolve. Multi-dimensional recurrences are another frontier.

This is of no consequence in your program currently, but the statement

r:= Vector[(N1+1)*N2+1];

in your procedure main doesn't do anything useful. If you did want to pre-allocate a Vector, the statement should be with ( ) instead of [ ].

subsindets(
     test1r2,
     `^`,
     x-> `if`(op(2,x) = 1/2,`if`(op(1,x)::`+`, `Math.Sqrt`(op(1,x)), x), `Math.Pow`(op(x)))
);

First 355 356 357 358 359 360 361 Last Page 357 of 395