Rouben Rostamian

MaplePrimes Activity

These are answers submitted by Rouben Rostamian

@erik10 See if this is what you want.


Removes all characters other than a-z and å, æ, ø (and their uppercase versions)

from the string str.  Returns a matrix of cols columns whose entries are the

remaining characters in str. The last row is padded with zeros if needed.

do_Danish := proc(str, cols)
        local len, syms, rows;
        uses Python;
        sprintf("re.split(\"[^a-zA-ZåæøÅÆØ]*\", %a)", str);
        remove(has, %, "");
        syms := convert~(%, symbol);
        len := nops(syms);
        print(convert(cat("number of chars = ", len), name));
        rows := iquo(len-1, cols) + 1;
        interface(rtablesize = max(rows, cols));
        Matrix(rows, cols, syms);
end proc:



Text := "This is a Dånish tæxtø: @X#!ÅÆØ";

"This is a Dånish tæxtø: @X#!ÅÆØ"

do_Danish(Text, 11);

`number of chars = 22`

Matrix(%id = 36893627851096899444)

do_Danish(Text, 16);

`number of chars = 22`

Matrix(%id = 36893627851096894868)

do_Danish(Text, 5);

`number of chars = 22`

Matrix(%id = 36893627851096883316)

Note: The message on the output says "number of chars = 22".  The "22" is shown properly in the worksheet but comes out broken on this website. Not my fault.




String S0 is given:

S0 := "This is a test. This is only a test";

"This is a test. This is only a test"

Remove all characters other than a-z:

S1 := Select~(IsLower, S0);


Convert S1 to a list of characters:

S2 := Explode(S1);

["h", "i", "s", "i", "s", "a", "t", "e", "s", "t", "h", "i", "s", "i", "s", "o", "n", "l", "y", "a", "t", "e", "s", "t"]

Optionally, convert the entries of S2 to symbols:

S3 := convert~(S2, symbol);

[h, i, s, i, s, a, t, e, s, t, h, i, s, i, s, o, n, l, y, a, t, e, s, t]

Put S3 into a matrx

Matrix(6,6, S3);

Matrix(6, 6, {(1, 1) = h, (1, 2) = i, (1, 3) = s, (1, 4) = i, (1, 5) = s, (1, 6) = a, (2, 1) = t, (2, 2) = e, (2, 3) = s, (2, 4) = t, (2, 5) = h, (2, 6) = i, (3, 1) = s, (3, 2) = i, (3, 3) = s, (3, 4) = o, (3, 5) = n, (3, 6) = l, (4, 1) = y, (4, 2) = a, (4, 3) = t, (4, 4) = e, (4, 5) = s, (4, 6) = t, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = 0, (5, 5) = 0, (5, 6) = 0, (6, 1) = 0, (6, 2) = 0, (6, 3) = 0, (6, 4) = 0, (6, 5) = 0, (6, 6) = 0})


If you solve the equation x^2 + y^2 = 4 for y, you will get two solutions, y=±sqrt(4 - x^2). The plus sign gives the equation of the upper half of the circle, and the minus sign gives the equation of the lower half. So the answer to Part (a) is y = sqrt(4 - x^2), and the plot is produced by

plot(sqrt(4 - x^2), x=-2..2, scaling=constrained);

As to part (b): Rotating that semicircle about the x axis produces a sphere of radius 2.

As to part (c): The volume enclosed by the sphere is given by the formula Vx that you have shown in your post. We have f(x) = sqrt(4 - x^2), and therefore f(x)^2 = 4 - x^2.  So the volume is:

V__x := Pi*int( 4 - x^2, x = -2 .. 2);


I haven't examined / debugged your code since it seems to me much too complicated for what it's supposd to do. Instead, I wrote the following alternative which does what you want. This is a slightly edited version of what I had initially posted.


We plot with the two cylinders in horizontal and vertical positions,
and then we rotate the picture by 45 degrees.

frame := proc(alpha)
        local O, R, L, get_dist, beta, a, b, A, B, P;
        uses plots, plottools;
        O := [0,0];
        R := 1;        # the length of the crankshaft's arm
        L := 4;        # the length of the connecting rod

        # distance of piston from the crankshaft's axis
        get_dist := theta -> R*cos(theta) + sqrt(L^2 - R^2*sin(theta)^2);

        a := get_dist(alpha);
        b := get_dist(Pi/2-alpha);
        P := [R*cos(alpha), R*sin(alpha)];
        A := [a,0];
        B := [0,b];

                circle(O, R, linestyle=longdash, color="Navy"),
                line(P, A, color="Green", thickness=4),
                line(P, B, color="Green", thickness=4),
                line(O, P, color="Green", thickness=4),
                line(1.5*[-R,0], 1.1*[R+L,0], linestyle=longdash),
                line(1.5*[0,-R], 1.1*[0,R+L], linestyle=longdash),
                pointplot([O, P], symbol=solidcircle, symbolsize=25,

                # the cylinders
                line([0.9*(L-R), -0.6*R], [1.1*(L+R), -0.6*R], thickness=8),
                line([0.9*(L-R),  0.6*R], [1.1*(L+R),  0.6*R], thickness=8),
                line([-0.6*R, 0.9*(L-R)], [-0.6*R, 1.1*(L+R)], thickness=8),
                line([ 0.6*R, 0.9*(L-R)], [ 0.6*R, 1.1*(L+R)], thickness=8),

                # the pistons
                line(A-[0,0.5*R], A+[0,0.5*R], color="Red", thickness=15),
                line(B-[0.5*R,0], B+[0.5*R,0], color="Red", thickness=15),
        rotate(%, Pi/4);
end proc:

nframes := 100:
frames := seq(frame(2*Pi*n/nframes), n=1..nframes):

plots:-display(frames, insequence, size=[600,400]);





The format of the font specification is defined in ?plot,options under the "font" entry. Your specification axesfont=[12,12] does not fit that specification. Maple does not complain about that in the worksheet mode. I would call that a shortcoming of the worksheet-mode parser.  The commandline-mode parser correctly flags it as invalid.

I suppose that by axesfont=[12,12]  you wish to select 12-point fonts for the horizontal and vertical axes.  To see that Maple's worksheet-mode parser interprets that differently, change that to axesfont=[36,8].  You will see that the "36" is ignored.



sys := { diff(x(t),t) = y(t), diff(y(t),t) = - x(t) };

{diff(x(t), t) = y(t), diff(y(t), t) = -x(t)}

eval(sys, { x(t) = r(t)*cos(theta(t)), y(t)=r(t)*sin(theta(t)) }):
solve(%, {diff(r(t),t), diff(theta(t),t)});

{diff(r(t), t) = 0, diff(theta(t), t) = -1}

The try/catch mechanism may be what you are looking for.


        print("before internal proc");
                if n<0 then
                        error "something";
        end proc(); #notice the (); at end
        print("after internal proc");
end proc:

Let's try:

try foo(3); (a+b)^2;  catch "something": (c+d)^2; end try;

"before internal proc"

"after internal proc"


try foo(-3); (a+b)^2;  catch "something": (c+d)^2; end try;

"before internal proc"



If you feel very enthusiastic, you may bundle up the try/catch along with foo
into a signle proc.


bar := proc(n::integer)
        local foo;
                print("before internal proc");
                        if n<0 then
                                error "something";
                end proc(); #notice the (); at end
                print("after internal proc");
        end proc:
        try foo(n); (a+b)^2;  catch "something": (c+d)^2; end try;
end proc:


Let's try:


"before internal proc"

"after internal proc"



"before internal proc"



Your code expresses the essence of the solution, but it can be streamlined a bit.

eq := <x, y> =~ lambda*<1, 1> + mu*<1, 2>;
convert(eq, set);
solve(%, {lambda, mu});

We see that solve() returns a unique solution, indicating that any vector <x,y> may be uniquely represented as a linear combination of <1,1> and <1,2>, indicating that those form a basis for the space.

Maple's PDF export has been broken in the last several releases. Despite repeated complaints on this forum, no solution seems to be forthcoming.

These two workarounds work quite well on the command-line in Linux.  The equivalent command lines may be available in Mac and Windows but I have neither so I wouldn't know.

  1. Workaround #1:  Save the graphics as EPS, let's say filename.eps, then do
        epstopdf filename.eps
    to produce filename.pdf.
  2. Workaround #2:  Save the graphics as SVG, let's say filename.svg, then do
        inkscape --export-type=pdf --export-area-drawing filename.svg
    to produce filename.pdf.

Both methods produce good quality PDF.  The file size of the PDF file in method #2 is about 1/20 of that of method #1 but the latter is more faithful to the original.

I have attached PDFs cooresponding to 
    plot3d(x^2+y^2, x=-1..1, y=-1..1);
converted through the two methods.



Here is the solution, but don't just pass it on to your teacher. She won't believe you.

To get an answer with detailed explanation, show what you know and how far you have gotten on your own on this homework.

f := x -> (x^3 + 9*x^2 - 9*x - 1) / (x^4 + 1);
numer(D(f)(x) - 1/2);
xvals := fsolve(%, x, maxsols=4);
seq(f(t) + 0.5*(x-t), t in xvals);
plot([f(x), %], x=-7..7, scaling=constrained, color=[seq(cat("oldplots ", i), i=1..5)]);

p1 := plot(sin(x), x=-2*Pi..2*Pi, color="Red"):
	plot(sin(x), x=-2*Pi..2*Pi, color="Green"),
	line([-2*Pi,0], [2*Pi,0]),
	line([0,-2*Pi], [0,2*Pi])
p2 := rotate(%, Pi/4):
display(p1,p2, scaling=constrained);

I don't see a simple way of adding tickmarks.

vertices := [
	c__1 = <0, -2>,
	c__2 = <1, 2>,
	c__3 = <2, 2>,
	c__4 = <0.5, 6>,
	c__5 = <1, 4> 
Labels := map( v -> [convert(rhs(v), list)[], lhs(v)], vertices):
	textplot(Labels, align={above}),
	plottools:-polygon(convert~(rhs~(vertices), list), style=line, color=red)


See for a lot of ideas on how to handle delay differential equations.


I don't see what you mean by tracing the moving points since the number of point changes in your sequence of plots. Here is how to draw traces of individual moving points that preserve their identities during the motion.

f := t -> sin(t);
g := t -> [cos(t), sin(t)];
trace_me := proc(t)
		pointplot([t,f(t)], symbol=solidcircle, symbolsize=30, color="Red"),
		plot(f(s), s=0..t, color="Green"),
		pointplot(g(t), symbol=solidcircle, symbolsize=30, color="Orange"),
		plot([g(s)[], s=0..t], color="Blue"),
end proc:
animate(trace_me, [t], t=0..2*Pi);

I will illustrate the required procedure in terms of a function that I made up. If this does not work in your case, then you need to provide more details about your function fp(x).



Here is a family of function of x defined in terms of a parameter p.

f := (x,p) -> (x-p)^2 + cos(p);

proc (x, p) options operator, arrow; (x-p)^2+cos(p) end proc

To calculate the family's envelope, we solve the following system
of two equations for the two unknowns x and y.  Call the solution X(p)

and Y(p).  The envelope is the parametric curve X(p), Y(p).

y = f(x,p), diff(f(x,p),p) = 0;
solve({%}, {x,y}):
X := unapply(eval(x, %), p);
Y := unapply(eval(y, %%), p);

y = (x-p)^2+cos(p), -2*x+2*p-sin(p) = 0

proc (p) options operator, arrow; p-(1/2)*sin(p) end proc

proc (p) options operator, arrow; (1/4)*sin(p)^2+cos(p) end proc

Let us plot the result.  The envelope is shown in blue.

        seq(plot(f(x,p), x=-10..10, color="Green", view=-1..2), p=-8..8, 0.3),
        plot([X(p),Y(p), p=-8..8], color="Blue", thickness=3),

We now calculate the area bounded by the central arch of the envelope and the x axis.
From the graph above we see that the arch extends roughly from x = -1 to x = 1.

To calculate the precise range, we seek parameter values that make Y(p) = 0

p_roots := solve(Y(p), p);

arctan(2*(-2+5^(1/2))^(1/2)/(-5^(1/2)+2))+Pi, -arctan(2*(-2+5^(1/2))^(1/2)/(-5^(1/2)+2))-Pi, arctan(2*(-2-5^(1/2))^(1/2), 5^(1/2)+2), arctan(-2*(-2-5^(1/2))^(1/2), 5^(1/2)+2)

and then calculate the corresponding x values:


[-arctan(2/(-2+5^(1/2))^(1/2))+Pi-(-2+5^(1/2))^(1/2), arctan(2/(-2+5^(1/2))^(1/2))-Pi+(-2+5^(1/2))^(1/2), arctan((2*I)*(5^(1/2)+2)^(1/2), 5^(1/2)+2)-I*(5^(1/2)+2)^(1/2), arctan(-(2*I)*(5^(1/2)+2)^(1/2), 5^(1/2)+2)+I*(5^(1/2)+2)^(1/2)]

[1.323245518, -1.323245518, 0.64379097e-1*I, -0.64379097e-1*I]

We conclude that the support of the arch is roughly in the range abs(x) < 1.323. The corresponding

parameter values are

p_roots[1], p_roots[2];

arctan(2*(-2+5^(1/2))^(1/2)/(-5^(1/2)+2))+Pi, -arctan(2*(-2+5^(1/2))^(1/2)/(-5^(1/2)+2))-Pi

The area bounded by a parametric curve and the x axis is given by int(Y(p)*(D(X))(p), p):

A := simplify(int(Y(p)*D(X)(p), p = p_roots[2] .. p_roots[1]));





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