Rouben Rostamian

MaplePrimes Activity


These are answers submitted by Rouben Rostamian

Printing that is the easy part:

for i from 1 to 3 do
  print(A^cat(`<`,i,`>`) = Mat(i));
end do;

A^`<1>` = Mat(1)

A^`<2>` = Mat(2)

A^`<3>` = Mat(3)

What you want to do with the result is something else.

@erik10 See if this is what you want.

restart;

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;
        ImportModule("re");
        sprintf("re.split(\"[^a-zA-ZåæøÅÆØ]*\", %a)", str);
        Python:-EvalString(%);
        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.

Download mw.mw

restart;

with(StringTools):

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);

"hisisatesthisisonlyatest"

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})

Download mw.mw

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.

restart;

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];

        display(
                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,
                    color="Orange"),


                # 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),
        scaling=constrained);
        rotate(%, Pi/4);
end proc:

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

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

 

 

Download piston-crank-animation2.mw

 

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.

 

restart;

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.

restart;

foo:=proc(n::integer)
        print("before internal proc");
        proc()
                if n<0 then
                        error "something";
                fi;
        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"

(a+b)^2

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

"before internal proc"

(c+d)^2

 

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

restart;

bar := proc(n::integer)
        local foo;
        foo:=proc(n::integer)
                print("before internal proc");
                proc()
                        if n<0 then
                                error "something";
                        fi;
                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:

bar(3);

"before internal proc"

"after internal proc"

(a+b)^2

bar(-3);

"before internal proc"

(c+d)^2

Download mw.mw

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

restart;
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.

parabola-from-eps.pdf
parabola-from-svg.pdf

 

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.

restart;
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)]);

restart;
with(plots):
with(plottools):
p1 := plot(sin(x), x=-2*Pi..2*Pi, color="Red"):
display(
	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.

restart;
with(plots):
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):
display(
	textplot(Labels, align={above}),
	plottools:-polygon(convert~(rhs~(vertices), list), style=line, color=red)
);

 

See https://www.mapleprimes.com/questions/229945-Simulation-Of-A-Solution-Of--Neutral 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.

restart;
with(plots):
f := t -> sin(t);
g := t -> [cos(t), sin(t)];
trace_me := proc(t)
	display(
		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"),
	scaling=constrained);
end proc:
animate(trace_me, [t], t=0..2*Pi);

First 13 14 15 16 17 18 19 Last Page 15 of 58