Items tagged with procedure


What i am trying to achieve is to evaluate the sequence as, shown, but from within a try-catch statement that handles and keeps a tally on the number and arguements for which the sequence encounters a division by zero error. ie, instead of haulting evaluation when each error is encountered, i want my code to record the index values at which the error occured, then continue on to the next term.




F := (-2*n[1]*n[3]-4*n[2]*n[1]*n[3]+4*n[2]*n[3]+4*n[3]*n[4]*n[1]+n[1])/(-n[1]-2*n[2]*n[1]+2*n[2]+2*n[4]*n[1]):

S := proc (N, M, G, L) options operator, arrow; [seq(seq(seq(seq(F, n[1] = N .. N), n[2] = M .. M), n[3] = G .. G), n[4] = L .. L)] end proc

proc (N, M, G, L) options operator, arrow; [seq(seq(seq(seq(F, n[1] = N .. N), n[2] = M .. M), n[3] = G .. G), n[4] = L .. L)] end proc


A := {}; -1; U := 0; -1; K := 0; -1; E := 0



J := 0:

H := 1



K[1] := J+H:

try S(K[1], K[2], K[3], K[4]) catch "numeric exception: division by zero": E := E+1; `union`({[K[1], K[2], K[3], K[4]]}, A) end try



J := 0:

H := 1



K[1] := J:

try S(K[1], K[2], K[3], K[4]) catch "numeric exception: division by zero": E := E+1; `union`({[K[1], K[2], K[3], K[4]]}, A) end try



J := 0:

H := 1



K[1] := J:

try S(K[1], K[2], K[3], K[4]) catch "numeric exception: division by zero": E := E+1; `union`({[K[1], K[2], K[3], K[4]]}, A) end try



{[0, 0, 1, 0]}


J := 0:

H := 1



K[1] := J:

try S(K[1], K[2], K[3], K[4]) catch "numeric exception: division by zero": E := E+1; `union`({[K[1], K[2], K[3], K[4]]}, A) end try



{[0, 0, 0, 1]}





Hi, there.

I have a program, and I want to make an interface where I can text in the figures and show the results. But I have no idea about this. Anyone can give me some instructions? Thanks!

I want to use a variant of the arctangent function in odeplot but I run into various problems. Here is the variant called at
> at := proc (x::realcons, yy)

if 0 < x then arctan(yy/x) elif x < 0 then Pi+arctan(yy/x) elif x = 0 then (1/2)*Pi end if end proc;

It would be nice to know if this is really what I want so I try to plot at  values for which I know the answer
> plot(at(-cos(-t), sin(t)), t = 0 .. 3.14);

Error, invalid input: at expects its 1st argument, x, to be of type realcons, but received -cos(t)

I have seen this problem before so I use single quotes with success:
plot('at(-cos(-t), sin(t))', t = 0 .. 3.14);

I get the desired plot;

Now I want to use this procedure in a plot of a numerical solution to an ODE.
The ODE is quite complicated but returns a procedure ,nans, that i use to visualize solutions via commands such as

> odeplot(nans, [[y, f(y)]], y = 0 .. 6);
No problem with any of that,

The problem arise when I define theta below
> theta := at(f(y)-(1/2)*Pi, diff(f(y), y));
and try to use it in odeplot, for example,
> odeplot(nans, [[y, theta]], y = 0 .. 6);
> theta1:=y->at(f(y)-Pi/(2),diff(f(y),y));

> odeplot(nans, [[y, theta1(y) ]], y = 0 .. 6);

Maple's complains about theta and theta1 and all of my attempts to fix the problem:

Error, (in plots/odeplot) curve 1 is not fully specified in terms of the ODE solution, found additional unknowns {Theta1}
Error, (in Theta1) invalid input: at expects its 1st argument, xx, to be of type realcons, but received f1(y)-(1/2)*Pi  or

Error, (in Theta1) invalid input: diff received HFloat(0.001), which is not valid for its 2nd argument

I supect there is an easy fix. If I give up on at and just use arctan I get an ugly jump in my plot but otherwise everything works.

I am looking for a high accuracy plot, however, and the jump obscures important features.

Please help!

I have a module with quite a few procedures and it is getting too long and complex. Basicially I write each procedure in a seperate document, them copy and paste it into the module. I want to improve matters as save each proc and read it in to the module

e.g.  Qdim:=proc(A,B).........end proc

        save Qdim , "Qdim.?"   have tried .txt ,.mla , .m  They save fine.

in the module have tried

read "Qdim.txt" etc.   I have included Qdim in export but Qdim doesnt work Qdim(A,B) returns Qdim(A,B)

read "C:\Users\Ronan\Documents\MAPLE\Rational Trinonometry\Qdim.m";

which procuces an error

Error, (in unknown) could not open `C:UsersRonanDocumentsMAPLERational TrinonometryQdim.m` for reading


what is the code to output every symbol assigned to a unique individual operator that is accepted by the maple interface, example what code can i assign to the function:


which will produce output in a list of single character strings

["*", "-","+","=",....]

I have a procedure that uses substitute. Below is my code

    ... #some calculatin

    subs([x[1] = 2, x[2] = 1], func);

end proc;
func:=5 + x[1]*x[2] + 10*x[1];

But when I call the procedure, her body is no substitution. What is the error? I can't understand what I did wrong?

Perhaps I am being stupid, but I have a problem with functional operators, more specifically with looping through a collection of them. Consider the following code (just a study case):

nonIdMaps := []:
for f in [x -> x,x -> 2*x,x -> 3*x] do
   if f(y) <> y then nonIdMaps := [nonIdMaps[],f] end if
end do;
nonIdMaps,map(f -> f(y),nonIdMaps);

There are two things I do not understand about this output: 1.) Why the f's rather than the specific maps as given in the list? 2.) Why two times 3*y in the last line, rather than [2*y,3*y]? (this issue being of course quite likely a consequence of the first one). This behaviour can be compared with the following:

nonIdMaps := select(f -> f(y) <> y,[x -> x,x -> 2*x,x -> 3*x]):
nonIdMaps,map(f -> f(y),nonIdMaps);

the output of which I do understand, being as I expected it to be. I guess that there are some scoping rules I do not understand, or what?

When we first started trying to use Maple to create a maple leaf like the one in the Canada 150 logo, we couldn’t find any references online to the exact geometry, so we went back to basics. With our trusty ruler and protractor, we mapped out the geometry of the maple leaf logo by hand.

Our first observation was that the maple leaf could be viewed as being comprised of 9 kites. You can read more about the meaning of these shapes on the Canada 150 site (where they refer to the shapes as diamonds).

We also observed that the individual kites had slightly different scales from one another. The largest kites were numbers 3, 5 and 7; we represented their length as 1 unit of length. Also, each of the kites seemed centred at the origin, but was rotated about the y-axis at a certain angle.

As such, we found the kites to have the following scales and rotations from the vertical axis:


1, 9: 0.81 at +/- Pi/2

2, 8: 0.77 at +/- 2*Pi/5

3, 5, 7: 1 at +/-Pi/4, 0

4, 6: 0.93 at +/- Pi/8

This can be visualized as follows:

To draw this in Maple we put together a simple procedure to draw each of the kites:

# Make a kite shape centred at the origin.
opts := thickness=4, color="#DC2828":
MakeKite := proc({scale := 1, rotation := 0})
    local t, p, pts, x;

    t := 0.267*scale;
    pts := [[0, 0], [t, t], [0, scale], [-t, t], [0, 0]]:
    p := plot(pts, opts);
    if rotation<>0.0 then
        p := plottools:-rotate(p, rotation);
    end if;
    return p;
end proc:


The main idea of this procedure is that we draw a kite using a standard list of points, which are scaled and rotated. Then to generate the sequence of plots:

shapes := MakeKite(rotation=-Pi/4),
          MakeKite(scale=0.77, rotation=-2*Pi/5),

          MakeKite(scale=0.81, rotation=-Pi/2),
          MakeKite(scale=0.93, rotation=-Pi/8),
          MakeKite(scale=0.93, rotation=Pi/8),
          MakeKite(scale=0.81, rotation=Pi/2),
          MakeKite(scale=0.77, rotation=2*Pi/5),
          plot([[0,-0.5], [0,0]], opts): #Add in a section for the maple leaf stem
plots:-display(shapes, scaling=constrained, view=[-1..1, -0.75..1.25], axes=box, size=[800,800]);

This looked pretty similar to the original logo, however the kites 2, 4, 6, and 8 all needed to be moved behind the other kites. This proved somewhat tricky, so we just simply turned on the point probe in Maple and drew in the connected lines to form these points.

shapes := MakeKite(rotation=-Pi/4),

          MakeKite(scale=0.81, rotation=-Pi/2),
          MakeKite(scale=0.81, rotation=Pi/2),
          plot([[0,-0.5], [0,0]], opts):
plots:-display(shapes, scaling=constrained, view=[-1..1, -0.75..1.25], axes=box, size=[800,800]);

Happy Canada Day!

Sorry for the simple subject.  Using unapply we can convert an expression to a function. 



               a:= x-> x^2+sin(x)

How do you go the other way.  That is convert a function to an expression?


I want to apply a rule to simplify an expression. The applyrule command works, when used directly in the worksheet. When I try to use the command within a procedure, Maple throws an error I cannot decipher:

Error, (in PatternMatching:-AlgStruct:-InsertPattern) first operand of `::' must be a name


Here is a full demonstration worksheet:








rmabssq := proc(inexp)
description "removes the abs^2 construct in an expression":
local ruleabssqared1,ruleabssqared2,outexp:
    ruleabssqared1:= abs(''a''::algebraic)^2= ''a''^2:
    ruleabssqared2:= abs('expand'(-''a'')::algebraic)^2= ''a'':
    outexp:= applyrule([ruleabssqared1,ruleabssqared2],inexp):
    return outexp:
end proc;

proc (inexp) local ruleabssqared1, ruleabssqared2, outexp; description "removes the abs^2 construct in an expression"; ruleabssqared1 := abs(''a''::algebraic)^2 = ''a''^2; ruleabssqared2 := abs((('expand')(-''a''))::algebraic)^2 = ''a''; outexp := applyrule([ruleabssqared1, ruleabssqared2], inexp); return outexp end proc


## does not work :(

Error, (in PatternMatching:-AlgStruct:-InsertPattern) first operand of `::' must be a name


## works!
ruleabssqared1:= abs(''a''::algebraic)^2= ''a''^2:
ruleabssqared2:= abs('expand'(-''a'')::algebraic)^2= ''a'':
newexp:= applyrule([ruleabssqared1,ruleabssqared2],anexp);






Thanks for your help

I am getting the following error while calculating function containing diffrential. Thankz in advance

KK := proc (x) options operator, arrow; diff(diff(x^2, x)) end proc;

proc (x) options operator, arrow; diff(diff(x^2, x)) end proc



Error, (in KK) invalid input: diff received 2, which is not valid for its 2nd argument




Download FUNCTION_(1).mw

I recently encontered a very strange result.

Lets define the procedure:

Fg := proc(x0,y0)
if (x0>=0)and(x0<=3) and (y0<=x0+2) and (y0>=x0-1) and (y0>=0) and (y0 <=3) then
return y0*(3-y0)*x0*(3-x0)*(x0+2-y0)*(y0-x0+1);
return 0;
end if:
end proc:

The plot looks like needed:

plot3d('Fg'(x,y), x=0..3, y=0..3);

But integration returns weird result:

evalf(Int('Fg'(x,y), [x=0..1, y=0..2.1]));


evalf(Int('Fg'(x,y), [x=0..1, y=0..2.2]));

Error, (in evalf/int) when calling 'Fg'. Received: 'cannot determine if this expression is true or false: 0 <= x and x <= 3 and y <= x+2 and x-1 <= y and 0 <= y and y <= 3'


I have two simple module's:

1) ------------------------------------------------------------------------

Point := proc(xx::float,yy::float)
    return module()
        local x := xx,y := yy;
        export ShowPoint,GetX,GetY;
        ShowPoint := proc()
            printf("Point X,Y -> [%f,%f]",x,y);
        end proc;

        GetX := proc()
            return x;
        end proc;        
        GetY := proc()
            return y;
        end proc;    
    end module:
end proc:

2) ------------------------------------------------------------------------

PointMath := module()
    option package;  
    export `+`;
    `+` := proc(a::Point(float,float),b::Point(float,float))
        option overload;
    end proc;
end module:


Next I use first module:



Finally I want to add above two points:



The results is:


Why is not called operator '+' and two points are not added?






I wrote some procedures in an older version of Maple to sort through a matrix and find repeated elements, and then set the matrix elements equal to one another. As an example, consider the matrix:

Matrix(4, 4, {(1, 1) = 31774769/38880000, (1, 2) = -90858559/233280000, (1, 3) = -76547233/69984000, (1, 4) = -119275567/139968000, (2, 1) = -90858559/233280000, (2, 2) = 1506841/6480000, (2, 3) = 442249/720000, (2, 4) = 85514221/116640000, (3, 1) = -76547233/69984000, (3, 2) = 442249/720000, (3, 3) = 592249771/349920000, (3, 4) = 121562339/87480000, (4, 1) = -119275567/139968000, (4, 2) = 85514221/116640000, (4, 3) = 121562339/87480000, (4, 4) = 170546323/87480000}, datatype = anything, storage = rectangular, order = Fortran_order, shape = [])
Due to its symmetric nature the upper triangular matrix is just the same as the lower triangular. i.e. the elements are equal: (2,1)=(1,2), (3,1)=(1,3) etc...

I have attached a minimal working example Maple script, which processes an input matrix, finds repeats and sets the elements equal to one another (e.g. [1,2]=[2,1], literally printing this) and saves the output to a file using a specific format for processing by another program. The matrix in the file is numeric but the actual matrices contain a lot of algebraic terms and can get quite large. This is where my procedures struggle as they take a very, very long time to process larger algebraic matrices to group the repeats. Is there a more Maple friendly way of going about this problem rather than these "archaic" procedures?

Here is the script:

Thank you in advance


I have a program:

Running abb(1,3) gives error: Error, (in abb) illegal use of a formal parameter

Might be a silly question: Is it not allowed? Do I have to define a local variable for b in order to change it?

1 2 3 4 5 6 7 Last Page 1 of 32