Rouben Rostamian

MaplePrimes Activity


These are answers submitted by Rouben Rostamian

I make a lot of animations with varying degrees of complexity.  I use Maple to generate frames, and I use ImageMagick to assemble the frames into an animation with complete control on everything.

ImageMagick is an extensive suite of software tools for image manipulation.  It is open and free.  I use it on Linux, but I understand that it also works on other platforms.  In all cases it is accessed through the command-line.

Here I will describe the steps needed to accomplish what you have asked.

  1. Save your Maple animation to an (animated) GIF file as you have described.  Let's call that file anim-raw.gif.
  2. Apply ImageMagick's convert command to split that file into individual frames:
          convert   anim-raw.gif   frame-%03d.gif
    This will write the individual frames into files named frame-000.gif through frame-nnn.gif.  If you have more that a 1000 frames, change the %03d to %04d.  That will write the files frame-0000.gif, etc.
  3. Now put together the individual frames into a single animated GIF called anim.gif:
          convert   -delay 10   -loop 2   frame-*.gif   anim.gif
    The "-loop 2" option says that we want to play the animation twice and then stop.  Change the 2 to anything you wish, or say "-loop 0" if you want the animation to play forever.
    The "-delay 10" option specifies the delay between frames.  The delay is measured in units of 1/100 of a second, so "-delay 10" means 1/10 of a second between frames.

I think that addresses all the questions that you have asked, and as we see, it takes just two commands typed on the command-line.

There are many more options available.  Consult ImageMagick's documentation.

 

 

 

 

It seems to me that your problem originates in TeXShop.  I don't have a Mac and I have no experience with TeXShop.  I do all my work on Linux, and with TeXLive which comes with it.

I downloaded your Konstruktion_Masterfile.mws, loaded it into Maple 2018, and saved the result as LaTeX through File->Export As...

Then compiled the resulting file through the command-line:

pdflatex Konstruktion_Masterfile.tex      # first pass
pdflatex Konstruktion_Masterfile.tex      # second pass

There were 6 error messages which I ingored.  They all were about missing { and } on line 4779.  I didn't try to fix those; you should be able to do it since you are familiar with the content. 

Here are Konstruktion_Masterfile.tex (which I have renamed Konstruktion_Masterfile.txt) and Konstruktion_Masterfile.pdf.  They look OK to me.

Konstruktion_Masterfile.txt
Konstruktion_Masterfile.pdf

 

restart;

I will solve the PDE in the domain 0 < x and x < 1, 0 < y and y < 1.  Solving in a general rectangular domain is no more difficult.

pde := diff(u(x, y),x,x) + diff(u(x,y),y,y) = 2*x^3 + 6*x*y*(1-y);

diff(diff(u(x, y), x), x)+diff(diff(u(x, y), y), y) = 2*x^3+6*x*y*(1-y)

bc1 := u(0,y) = 0, u(1, y) = y*(1-y);

u(0, y) = 0, u(1, y) = y*(1-y)

bc2 := u(x,0) = 0, u(x,1) = 0;

u(x, 0) = 0, u(x, 1) = 0

In view of bc2, the solution may be expressed in a Fourier series in the y variable, where the coefficients f__k(x) are to be determined:

sol := u(x,y) = Sum(f[k](x)*sin(k*Pi*y), k=1..infinity);

u(x, y) = Sum(f[k](x)*sin(k*Pi*y), k = 1 .. infinity)

The boundary conditions bc2 are already satisfied.  This solution candidate should satisfy the pde and the boundary conditions bc1.

Step 1:  Let's look at bc1.  The first equation in bc1 says that:

eval(rhs(sol), x=0) = rhs(bc1[1]);

Sum(f[k](0)*sin(k*Pi*y), k = 1 .. infinity) = 0

which then implies that

ic1 := f[k](0) = 0;

f[k](0) = 0

Step 2:  The second equation in bc1 says that

tmp := eval(rhs(sol), x=1) = rhs(bc1[2]);

Sum(f[k](1)*sin(k*Pi*y), k = 1 .. infinity) = y*(1-y)

To determine the f__k(1) from here, we multiply the equation by sin(n*Pi*y) and integrate:

Int(lhs(tmp)*sin(n*Pi*y), y=0..1) = Int(rhs(tmp)*sin(n*Pi*y), y=0..1);

Int((Sum(f[k](1)*sin(k*Pi*y), k = 1 .. infinity))*sin(n*Pi*y), y = 0 .. 1) = Int(y*(1-y)*sin(n*Pi*y), y = 0 .. 1)

The sum of the left-hand side reduces to a single term because the integral of sin(k*Pi*y)*sin(n*Pi*y) is zero when k <> n.  The integral on the right-hand side is easy to calculate.  We thus arrive at

int(f[k](1)*sin(k*Pi*y)^2, y=0..1) = int(y*(1-y)*sin(k*Pi*y), y=0..1) assuming k::integer:
ic2 := isolate(%, f[k](1));

f[k](1) = 4*(-(-1)^k+1)/(k^3*Pi^3)

Step 3:  Plug the solution candidate u(x, y) into he pde:

tmp := eval(pde, sol);

Sum((diff(diff(f[k](x), x), x))*sin(k*Pi*y), k = 1 .. infinity)+Sum(-f[k](x)*k^2*Pi^2*sin(k*Pi*y), k = 1 .. infinity) = 2*x^3+6*x*y*(1-y)

Multiply this by sin(n*Pi*y) and integrate.

Int(lhs(tmp)*sin(n*Pi*y), y=0..1) = Int(rhs(tmp)*sin(n*Pi*y), y=0..1);

Int((Sum((diff(diff(f[k](x), x), x))*sin(k*Pi*y), k = 1 .. infinity)+Sum(-f[k](x)*k^2*Pi^2*sin(k*Pi*y), k = 1 .. infinity))*sin(n*Pi*y), y = 0 .. 1) = Int((2*x^3+6*x*y*(1-y))*sin(n*Pi*y), y = 0 .. 1)

The infinite summations reduce to single terms as before.  The right-hand side may be evaluated explictly.  We this arrive at:

ode := 1/2*(diff(f[k](x),x,x) - k^2*Pi^2*f[k](x)) = int(rhs(tmp)*sin(k*Pi*y), y=0..1) assuming k::integer;

(1/2)*(diff(diff(f[k](x), x), x))-(1/2)*k^2*Pi^2*f[k](x) = 2*(Pi^2*k^2*x^2+6)*x*(-(-1)^k+1)/(k^3*Pi^3)

Step 4:  We solve this ode along with the boundary conditions which we obtained in steps 1 and 2.

dsol := dsolve({ode, ic1, ic2});

f[k](x) = -8*exp(k*Pi*x)*((-1)^k*Pi^2*k^2-k^2*Pi^2+6*(-1)^k-6)/(Pi^5*k^5*(exp(k*Pi)-exp(-k*Pi)))+8*exp(-k*Pi*x)*((-1)^k*Pi^2*k^2-k^2*Pi^2+6*(-1)^k-6)/(Pi^5*k^5*(exp(k*Pi)-exp(-k*Pi)))+4*((-1)^k-1)*x*(Pi^2*k^2*x^2+12)/(Pi^5*k^5)

Conclusion: The solution of the PDE is

mysol := eval(sol, dsol);

u(x, y) = Sum((-8*exp(k*Pi*x)*((-1)^k*Pi^2*k^2-k^2*Pi^2+6*(-1)^k-6)/(Pi^5*k^5*(exp(k*Pi)-exp(-k*Pi)))+8*exp(-k*Pi*x)*((-1)^k*Pi^2*k^2-k^2*Pi^2+6*(-1)^k-6)/(Pi^5*k^5*(exp(k*Pi)-exp(-k*Pi)))+4*((-1)^k-1)*x*(Pi^2*k^2*x^2+12)/(Pi^5*k^5))*sin(k*Pi*y), k = 1 .. infinity)

eval(rhs(mysol), infinity=30):
plot3d(%, x=0..1, y=0..1, style=patchcontour);


 

Download mw1.mw

restart;

pde := diff(u(x,y),x,x) + diff(u(x,y),y,y)
          = 2*Pi*(2*Pi*y^2 - 2*Pi*y - 1) * exp(Pi*y*(1-y)) * sin(Pi*x);

diff(diff(u(x, y), x), x)+diff(diff(u(x, y), y), y) = 2*Pi*(2*Pi*y^2-2*Pi*y-1)*exp(Pi*y*(1-y))*sin(Pi*x)

bc1 := u(0,y) = sin(Pi*y),  u(1,y) = exp(Pi)*sin(Pi*y);
bc2 := u(x,2) = exp(-2*Pi)*sin(Pi*x),  u(x,0) = u(x,1);

u(0, y) = sin(Pi*y), u(1, y) = exp(Pi)*sin(Pi*y)

u(x, 2) = exp(-2*Pi)*sin(Pi*x), u(x, 0) = u(x, 1)

The function "z(x.,y)=e^(Pi x) sin(Pi y)" satisfies the boundary conditions bc1, therefore

we change the independent variable from u to v through u(x, y) = z(x, y)+v(x, y),

Then v(x, y) would satisfy the homogeneous boundary conditions v(0, y) = 0, v(1, y) = 0.  

z := (x,y) -> exp(Pi*x)*sin(Pi*y);

proc (x, y) options operator, arrow; exp(Pi*x)*sin(Pi*y) end proc

pde_v := eval(pde, u(x,y) = z(x,y) + v(x,y));

diff(diff(v(x, y), x), x)+diff(diff(v(x, y), y), y) = 2*Pi*(2*Pi*y^2-2*Pi*y-1)*exp(Pi*y*(1-y))*sin(Pi*x)

In view of v's homogeneous boundary condition, we may express it in a Fourier series,
that is, an infinite sum of the form "(&sum;)`f__k`(y)*sin(k Pi x)."   However, the right-hand

side of the pde_v has only sin(Pi*x), therefore the infinite sum collapses to a single term.

Thus, we look for a solution of the pde_v in the form v(x, y) = f(y)*sin(Pi*x):

eval(pde_v, v(x,y)=f(y)*sin(Pi*x)):
ODE := simplify(%/sin(Pi*x));

-f(y)*Pi^2+diff(diff(f(y), y), y) = 4*(-1/2+(y^2-y)*Pi)*Pi*exp(-Pi*y*(-1+y))

Thus the problem has been reduced to the solution of an ODE.

dsol := dsolve(ODE);

f(y) = exp(Pi*y)*_C2+exp(-Pi*y)*_C1+exp(-Pi*y*(-1+y))

and we arrive at the solution of {pde + bc1}

mysol := u(x,y) = eval(f(y), dsol) * sin(Pi*x) + z(x,y);

u(x, y) = (exp(Pi*y)*_C2+exp(-Pi*y)*_C1+exp(-Pi*y*(-1+y)))*sin(Pi*x)+exp(Pi*x)*sin(Pi*y)

We apply the boundary conditions bc2 to determine _C1 and _C2.  We have:

simplify(eval(mysol, y=2) - bc2[1]);

0 = sin(Pi*x)*(exp(2*Pi)*_C2+exp(-2*Pi)*_C1)

For this to hold for all x, we need _C1 = _C2 = 0.  Thus mysol reduces to:

mysol := eval(mysol, {_C1=0, _C2=0});

u(x, y) = exp(-Pi*y*(-1+y))*sin(Pi*x)+exp(Pi*x)*sin(Pi*y)

We have yet to apply the second condition in bc2, but there is no more freedom in

mysol.  But not to worry -- the problem is artificially concocted so that the second

condition in bc2 is automatically satisfied:

eval(mysol, y=0) - eval(mysol, y=1);

u(x, 0)-u(x, 1) = 0

Conclusion:  The solution is:

mysol;

u(x, y) = exp(-Pi*y*(-1+y))*sin(Pi*x)+exp(Pi*x)*sin(Pi*y)

pdetest(mysol, {pde, bc1, bc2});

{0}

 

 

Download mw.mw

restart;
r := 3;   # change as needed
M := Matrix(r):
assign(seq('M'[r+1-i,i]=1/i, i=1..r)):
U := Vector(r, i -> 1/i):
V := Vector(r, i -> 1/(r+1-i)):
Z := Matrix(r):
A := < Z,   -V,   M;
       V^+,  Pi, -U^+;
      -M^+,  U,   Z  >;

r := 3

Matrix(%id = 18446884280553062262)

 

 

Download make_matrix.mw

Before entering the for-loop, define;

mycolors := ["black", "blue", "red", "pink"];

Then specify the color in the for-loop:

for k to 4 do
  R := dsolve(eval({bc, sys}, Ha = L[k]), fcns, type = numeric, AP);
  AP := approxsoln = R;
  p1u[k] := odeplot(R, [y, U(y)], 0 .. 1, numpoints = 100,
      labels = ["y", "U"], style = line, color = mycolors[k]);
end do;

Alternatively, you may omit the color option in the loop, and apply the colors to the composite plot, as in;

display([p1u[1], p1u[2], p1u[3], p1u[4]], color=mycolors);

but note that in the first argument of display I have changed your curly braces to square brackets.

 

Kitonum has already shown how to compute the derivative for a specific function f. I just want to add that specifying the f is not necessary.  It can be done for any f:

restart;
D[1](f)(z*sqrt(a/nu[f]), U*t/(2*x));

restart;
with(Student[MultivariateCalculus]):
r := (phi,theta) -> <(cos(phi)+3)*cos(theta), (cos(phi)+3)*sin(theta), sin(phi)>;
SurfaceArea(Surface(r(phi,theta), phi=0..2*Pi, theta=0..2*Pi));

The answer is 12 π2.

I don't have GlobalOptimization, but that does not seem to be an impediment. The basic minimize() works quite well.

restart;

sigmaF:=u->piecewise(u < -1,-1,u >1,1,u);

sigmaF := proc (u) options operator, arrow; piecewise(u < -1, -1, 1 < u, 1, u) end proc

Fun:=proc(x1,x2,u1,u2)
        2*x1*(1+x2)*sigmaF(u1)+(1+x2^2)*sigmaF(u2);
end proc:

minimize(Fun(x1,x2,u1,u2), x1=-5..5, x2=-10..100, u1=-1..1, u2=-1..1, location);

-11011, {[{u1 = -1, u2 = -1, x1 = 5, x2 = 100}, -11011], [{u1 = 1, u2 = -1, x1 = -5, x2 = 100}, -11011]}

 

As to plotting, I don't understand the question.  Fun is a function of four variables.  How do you expect to plot a function of four variables?  Furthermore, how is that question related to the minimization issue?

 

After you have solved the PDE, as in sol := pdsolve(...), do
U := sol:-value():
U(2.0, 3.0);
U(2.0, 3.1);

restart;
M := 5;
F := Matrix(M+1,M+1):
for r from 2 to M+1 do
  for s from 1 to r-1 do
    if type(r+s, odd) then
      F[r,s] := 2^(k+1)*sqrt((2*r-1)*(2*s-1));
    end if
  end do
end do:
evalm(F);

 

That error message manifests a "misunderstanding" by Maple but it appears to be harmless.  Introduce a third parameter, k, and assign it an arbitrary value and Maple produces the correct result:

restart;
f:=x->piecewise(x>=-1/2 and x<=1/2,1);
eq:={diff(x(t),t)-sum(f(t-k*T),k=0..K)*x(t)=0,x(0)=1};
sol:=dsolve(eq, numeric, parameters=[T,K,k]);
sol(parameters=[1,3,-1]);  # the third argument is an arbitrary number
plots:-odeplot(sol, [t, x(t)], t=0..6,
    color=red, thickness=3, view=0..40
);

Or with a more interesting choice of parameters:

sol(parameters=[2,2,-1]);  # the third argument is an arbitrary number
plots:-odeplot(sol, [t, x(t)], t=0..8,
    color=red, thickness=3, view=0..13);

 

restart;

A sample constraint function.  Replace as needed:

f := (x,y) -> 2*y^2 + x - 1;

proc (x, y) options operator, arrow; 2*y^2+x-1 end proc

The constraint equation.  Change as needed:

constr_eq := unapply(f(x,y)=0.01, [x,y]);

proc (x, y) options operator, arrow; 2*y^2+x-1 = 0.1e-1 end proc

Does the equivalent of the (non-existent) command

seq(f(x,y)=0.01, x=0..1, y=0..1, 0.1);

doit := proc(xrange, yrange, stepsize)
  local i, x, y, n, xmin, xmax;
  xmin := evalf(op(1,xrange));
  xmax := evalf(op(2,xrange));
  n := 1 + round((xmax - xmin)/stepsize);
  for i from 0 to n do
    x[i] := (n-i)/n*xmin + i/n*xmax;
    # assume there is /exactly/ one solution to the following:
    y[i] := fsolve(constr_eq(x[i],yval), yval=yrange);
  end do;
  return [seq([x[i],y[i]], i=0..n)];
end proc:

ans := doit(0..1, 0..1, 0.1);

[[0., .7106335202], [0.9090909091e-1, .6778978201], [.1818181818, .6434989581], [.2727272727, .6071543162], [.3636363636, .5684908251], [.4545454546, .5269983612], [.5454545454, .4819468096], [.6363636364, .4322246890], [.7272727273, .3759835586], [.8181818182, .3096919290], [.9090909091, .2246208927], [1., 0.7071067812e-1]]

 

 

Download mw.mw

Write the summation as

sum( irem(s+r,2) * whatever, s=1 .. r-1);

because irem(s+r,2) is zero when s+r is even, and one otherwise.

 

Asking for a phase portrait for your equation is not exactly meaningful.  The responses that you have received present graphs of solutions y(x) versus x, which is not the usual meaning of a phase portrait.  A phase portrait is a plot in the phase space.

The concept of the phase space, however, pertains to autonomous differential equations.  Your equation is non-autonomous, so the graphs that you have been presented with are remotely reminiscent of phase portraits but you should be aware that they are not phase portraits.

That said, here is what I would do if I were to plot a set of graphs of y(x) versus x (not a phase portrait).

restart;

with(DEtools):

de := diff(y(x),x)=x^2-y(x)^2;

diff(y(x), x) = x^2-y(x)^2

a := 2.0;  b := 3.0;

2.0

3.0

ic := seq(y(s)=+a, s=-a..a, 0.3),
      seq(y(s)=-a, s=-a..a, 0.3),
      seq(y(-a)=s, s=-a..a, 0.3),
      seq(y(+a)=s, s=-a..a, 0.3):

DEplot(de, y(x), x=-b..b, [ic], y=-b..b,
    linecolor=black, thickness=1, arrows=none);


 

Download mw.mw

First 34 35 36 37 38 39 40 Last Page 36 of 58