Rouben Rostamian

MaplePrimes Activity


These are answers submitted by Rouben Rostamian

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

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

restart;

with(plots):

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.

display(
        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),
size=[700,500]);

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:

simplify(X~([p_roots]));
evalf(%);

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

(7/3)*(-2+5^(1/2))^(1/2)+(5/6)*(-2+5^(1/2))^(1/2)*5^(1/2)+(1/4)*arctan(2*(-2+5^(1/2))^(1/2)*(5^(1/2)+2))-(1/4)*Pi

evalf(A);

1.586776254
 

Download area-under-envelope.mw

You are interpreting Maple's result as if it had said y(x) = whatever.  But that's not what the answer says.  Rather, the answer is an integral with the upper limit as y(x).  The following worksheet shows how to verify that Maple's solution does indeed satisfy the differential equation.

restart;

ode := diff(y(x), x, x) = - sin(y(x));   # the minus sign is missing in the original worksheet!

diff(diff(y(x), x), x) = -sin(y(x))

dsol := dsolve(ode);

Intat(1/(2*cos(_a)+_C1)^(1/2), _a = y(x))-x-_C2 = 0, Intat(-1/(2*cos(_a)+_C1)^(1/2), _a = y(x))-x-_C2 = 0

Let us verify that dsol[1] is a solution of the ode.  (dsol[2] may be verified in the same way)

diff(dsol[1], x);
isolate(%, diff(y(x), x));
diff(%, x);
applyop(eval, 2, %, %%);

(diff(y(x), x))/(2*cos(y(x))+_C1)^(1/2)-1 = 0

diff(y(x), x) = (2*cos(y(x))+_C1)^(1/2)

diff(diff(y(x), x), x) = -(diff(y(x), x))*sin(y(x))/(2*cos(y(x))+_C1)^(1/2)

diff(diff(y(x), x), x) = -sin(y(x))

 

 

Download mw.mw

If we plot the left-hand side and right-hand side expressions of your equation, we see that the plots don't intersect, and therefore there is no (real) solution to your equation.

eq := exp(x) * (1 + sqrt(1 + exp(-2*x))) - arcsinh(exp(-x)) = x;
plot([lhs(eq), rhs(eq)], x=-3..3);

Here is how to go about it.  The resulting figure is not exactly like what you have shown which indicates that your figure was produced based on a different set of parameters than what you have provided.

restart;

We have five differential equations:

de1 := diff(u__1(y),y,y) + 1/2*diff(N(y),y) + 1/2*theta__1(y) = 0;

diff(diff(u__1(y), y), y)+(1/2)*(diff(N(y), y))+(1/2)*theta__1(y) = 0

de2 := diff(N(y),y,y) - 2/3 * (2*N(y) + diff(u__1(y),y)) = 0;

diff(diff(N(y), y), y)-(4/3)*N(y)-(2/3)*(diff(u__1(y), y)) = 0

de3 := diff(theta__1(y),y,y) = 0;

diff(diff(theta__1(y), y), y) = 0

de4 := diff(u__2(y),y,y) + theta__2(y) = 0;

diff(diff(u__2(y), y), y)+theta__2(y) = 0

de5 := diff(theta__2(y),y,y) = 0;

diff(diff(theta__2(y), y), y) = 0

Find the general solution:

dsol := dsolve({de1,de2,de3,de4,de5});

{N(y) = exp(y)*_C2-exp(-y)*_C3+(1/3)*_C10*y+(1/6)*_C9*y^2+_C4, u__1(y) = -2*_C4*y-(1/3)*_C10*y^2-(1/9)*_C9*y^3-(1/2)*exp(y)*_C2-(1/2)*exp(-y)*_C3+(1/2)*_C9*y+_C1, u__2(y) = -(1/6)*_C7*y^3-(1/2)*_C8*y^2+_C5*y+_C6, theta__1(y) = _C9*y+_C10, theta__2(y) = _C7*y+_C8}

How many integrations constants?

indets(dsol, name);

{_C1, _C10, _C2, _C3, _C4, _C5, _C6, _C7, _C8, _C9, y}

So there are 10 integration constants, which is good since we have 10 boundary and interface conditions.

 

For now, let us extract the individual solutions of the ODE system:

u__1 := 'u__1':
eval(u__1(y), dsol):
u__1 := unapply(%, y);

proc (y) options operator, arrow; -2*_C4*y-(1/3)*_C10*y^2-(1/9)*_C9*y^3-(1/2)*exp(y)*_C2-(1/2)*exp(-y)*_C3+(1/2)*_C9*y+_C1 end proc

u__2 := 'u__2':
eval(u__2(y), dsol):
u__2 := unapply(%, y);

proc (y) options operator, arrow; -(1/6)*_C7*y^3-(1/2)*_C8*y^2+_C5*y+_C6 end proc

theta__1 := 'theta__1':
eval(theta__1(y), dsol):
theta__1 := unapply(%, y);

proc (y) options operator, arrow; _C9*y+_C10 end proc

theta__2 := 'theta__2':
eval(theta__2(y), dsol):
theta__2 := unapply(%, y);

proc (y) options operator, arrow; _C7*y+_C8 end proc

N := 'N':
eval(N(y), dsol):
N := unapply(%, y);

proc (y) options operator, arrow; exp(y)*_C2-exp(-y)*_C3+(1/3)*_C10*y+(1/6)*_C9*y^2+_C4 end proc

Now let us look at the boundary condtions.

 

Boundary conditions on the interval (-1,0):

bc[-1] := u__1(-1) = 0, N(-1) = 0, theta__1(-1) = 1,
        u__1(0) = u__0, theta__1(0) = theta__0, D(theta__1)(0) = theta_d;

2*_C4-(1/3)*_C10-(7/18)*_C9-(1/2)*exp(-1)*_C2-(1/2)*exp(1)*_C3+_C1 = 0, exp(-1)*_C2-exp(1)*_C3-(1/3)*_C10+(1/6)*_C9+_C4 = 0, -_C9+_C10 = 1, -(1/2)*_C2-(1/2)*_C3+_C1 = u__0, _C10 = theta__0, _C9 = theta_d

Boundary conditions on the interval (0,1)

bc[1] := u__2(1) = 0, theta__2(1) = 0;

-(1/6)*_C7-(1/2)*_C8+_C5+_C6 = 0, _C7+_C8 = 0

Interface conditions at  y = 0

bc[0] := u__1(0) = u__2(0), D(N)(0) = 0, theta__1(0) = theta__2(0),  D(theta__1)(0) = D(theta__2)(0),
        D(u__1)(0) + 1/2*N(0) = 1/2*D(u__2)(0);

-(1/2)*_C2-(1/2)*_C3+_C1 = _C6, _C2+_C3+(1/3)*_C10 = 0, _C10 = _C8, _C9 = _C7, -(3/2)*_C4+(1/2)*_C9 = (1/2)*_C5

Apply the 10 boundary and interface conditions to determine the 10 integration coefficients:

c_vals := solve({bc[-1], bc[0], bc[1]});

{_C1 = -(1/6)*(6*exp(-1)*exp(1)-21*exp(-1)-5*exp(1))/(11*exp(-1)+9*exp(1)), _C10 = 1/2, _C2 = -(1/18)*(27*exp(1)-67)/(11*exp(-1)+9*exp(1)), _C3 = -(1/18)*(33*exp(-1)+67)/(11*exp(-1)+9*exp(1)), _C4 = -(1/36)*(12*exp(-1)*exp(1)+35*exp(-1)+53*exp(1))/(11*exp(-1)+9*exp(1)), _C5 = (1/12)*(12*exp(-1)*exp(1)-31*exp(-1)-exp(1))/(11*exp(-1)+9*exp(1)), _C6 = -(1/12)*(12*exp(-1)*exp(1)-53*exp(-1)-19*exp(1))/(11*exp(-1)+9*exp(1)), _C7 = -1/2, _C8 = 1/2, _C9 = -1/2, theta_d = -1/2, u__0 = -(1/12)*(12*exp(-1)*exp(1)-53*exp(-1)-19*exp(1))/(11*exp(-1)+9*exp(1)), theta__0 = 1/2}

Evaluate u1 and u2

my_u1 := eval(u__1(y), c_vals);
my_u2 := eval(u__2(y), c_vals);

(1/18)*(12*exp(-1)*exp(1)+35*exp(-1)+53*exp(1))*y/(11*exp(-1)+9*exp(1))-(1/6)*y^2+(1/18)*y^3+(1/36)*exp(y)*(27*exp(1)-67)/(11*exp(-1)+9*exp(1))+(1/36)*exp(-y)*(33*exp(-1)+67)/(11*exp(-1)+9*exp(1))-(1/4)*y-(1/6)*(6*exp(-1)*exp(1)-21*exp(-1)-5*exp(1))/(11*exp(-1)+9*exp(1))

(1/12)*y^3-(1/4)*y^2+(1/12)*(12*exp(-1)*exp(1)-31*exp(-1)-exp(1))*y/(11*exp(-1)+9*exp(1))-(1/12)*(12*exp(-1)*exp(1)-53*exp(-1)-19*exp(1))/(11*exp(-1)+9*exp(1))

plots:-display(
        plot(my_u1, y=-1..0, color=red),
        plot(my_u2, y=0..1, color=blue)
);

 

Download mw.mw

 

First 9 10 11 12 13 14 15 Last Page 11 of 53