Rouben Rostamian

MaplePrimes Activity


These are answers submitted by Rouben Rostamian

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

restart;

with(LinearAlgebra):

A := <
1, 0, 0, 1;
0, -1, 1, 0;
0, 1, -1, 0;
1, 0, 0, 1 >;

_rtable[18446884057743726822]

Here are A's eigenvalues and eigenvectors:

evals, U := Eigenvectors(A);

evals, U := Vector(4, {(1) = -2, (2) = 2, (3) = 0, (4) = 0}), Matrix(4, 4, {(1, 1) = 0, (1, 2) = 1, (1, 3) = -1, (1, 4) = 0, (2, 1) = -1, (2, 2) = 0, (2, 3) = 0, (2, 4) = 1, (3, 1) = 1, (3, 2) = 0, (3, 3) = 0, (3, 4) = 1, (4, 1) = 0, (4, 2) = 1, (4, 3) = 1, (4, 4) = 0})

Make a diagonal matrix of the eigenvalues:

Lambda := DiagonalMatrix(evals);

_rtable[18446884057743703326]

We have A = U.Lambda.(1/U).  Let's verify that:

A - U . Lambda . U^(-1);

_rtable[18446884057743692134]

Here are two equivalent ways of calculating e^A.

 

Method 1:

U . MatrixExponential(Lambda) . U^(-1);

_rtable[18446884057743684062]

Method 2 (the preferred way) does not require explicitly calculating eigenvalues and eigenvectors:

MatrixExponential(A);

_rtable[18446884057743676950]

Download mw.mw

Define φ and ψψ as you already have.

Then:

r := 2^k * M;
phi_vec := Vector[column](r, i-> phi[i]);
`&psi;&psi;_vec` := Vector[row](r, j-> `&psi;&psi;`[j]);
P := phi_vec . `&psi;&psi;_vec`;

 

Aside: The symbol `&psi;&psi;` in your calculations is too cumbersome and unnecessary. Why not use a single-letter symbol such as an uppercase Ψ insteaad?

Here is a worksheet that shows the general method of assembling a matrix from smaller matrices.

I must alert you, however, to your use of M^(−1) *~ K in your worksheet. That certainly IS NOT the same as the matrix product M^(−1) . K. Which of those constructions do you have in mind?

restart;

with(LinearAlgebra):

r := 2;

2

Putting fiour rxr arbitrary matrices together:

< Matrix(r, symbol=a), Matrix(r, symbol=b);
  Matrix(r, symbol=c), Matrix(r, symbol=d) >;

_rtable[18446884266110072342]

Putting fiour rxr matrices together, the first two being the zero matrix and the identity matrix:

< ZeroMatrix(r), IdentityMatrix(r);
  Matrix(r, symbol=c), Matrix(r, symbol=d) >;

_rtable[18446884266110064990]

Download mw.mw

restart;

z := sin(2*x+3*y);

sin(2*x+3*y)

z_tmp := subs(2*x=freeze(2*x), 3*y=freeze(3*y), z);

sin(`freeze/R0`+`freeze/R1`)

thaw(expand(z_tmp));

sin(2*x)*cos(3*y)+cos(2*x)*sin(3*y)

First 30 31 32 33 34 35 36 Last Page 32 of 53