Carl Love

Carl Love

28025 Reputation

25 Badges

12 years, 307 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

Let the expression be expr. Then do

op(indets(expr, specfunc(anything, RootOf))[1]);

Yes, it is easy with plotsetup(window). See help pages ?plot,device and ?plotsetup .

Your question is barely readable. In the future, enter your matrix into Maple and then cut-and-paste the matrix into your post.

I hope that you can draw your conclusions from the following worksheet. If not, ask for more help.


restart:

A:= < k+3, 2, k-4, 3;
      0,   2,  -9, 5;
      0,   0, k^2+k-2, k-1 >;  

A := Matrix(3, 4, {(1, 1) = k+3, (1, 2) = 2, (1, 3) = k-4, (1, 4) = 3, (2, 1) = 0, (2, 2) = 2, (2, 3) = -9, (2, 4) = 5, (3, 1) = 0, (3, 2) = 0, (3, 3) = k^2+k-2, (3, 4) = k-1})

(1)

eval(A, k=1);

Matrix(3, 4, {(1, 1) = 4, (1, 2) = 2, (1, 3) = -3, (1, 4) = 3, (2, 1) = 0, (2, 2) = 2, (2, 3) = -9, (2, 4) = 5, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0})

(2)

solve(A[3,3] = 0, {k});

{k = 1}, {k = -2}

(3)

eval(A, k= -2);

Matrix(3, 4, {(1, 1) = 1, (1, 2) = 2, (1, 3) = -6, (1, 4) = 3, (2, 1) = 0, (2, 2) = 2, (2, 3) = -9, (2, 4) = 5, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = -3})

(4)

 


Download Parametric_linear_system.mw

 

 


restart:

Notice the use of  `*` instead of implied multiplication

Sys:=
     4*x1 + 2*x2 - 7*x3 - 11*x4 = 5,

     2*x1 + 1*x2 - 2*x3 - 4*x4 = 2,

     4*x1 + 2*x2 - 10*x3 - 14*x4 = 6
:

X:= [x||(1..4)]:

A:= LinearAlgebra:-GenerateMatrix([Sys], X, augmented);

A := Matrix(3, 5, {(1, 1) = 4, (1, 2) = 2, (1, 3) = -7, (1, 4) = -11, (1, 5) = 5, (2, 1) = 2, (2, 2) = 1, (2, 3) = -2, (2, 4) = -4, (2, 5) = 2, (3, 1) = 4, (3, 2) = 2, (3, 3) = -10, (3, 4) = -14, (3, 5) = 6})

(1)

R:= LinearAlgebra:-ReducedRowEchelonForm(A);

R := Matrix(3, 5, {(1, 1) = 1, (1, 2) = 1/2, (1, 3) = 0, (1, 4) = -1, (1, 5) = 2/3, (2, 1) = 0, (2, 2) = 0, (2, 3) = 1, (2, 4) = 1, (2, 5) = -1/3, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0, (3, 5) = 0})

(2)

Sol:= LinearAlgebra:-LinearSolve(A, free= t);

Sol := Vector(4, {(1) = t[1], (2) = -2*t[1]+4/3+2*t[4], (3) = -1/3-t[4], (4) = t[4]})

(3)

The solution space is two-dimensional. Verify the solution by plugging into the original system of equations.

eval(Sys, X =~ convert(Sol, list));

5 = 5, 2 = 2, 6 = 6

(4)

 


Download Linear_system.mw

Use command residue. For example

residue(1/z, z= 0);

     1

The problem is that you are using m in two different ways. You are using it as an index to the middle add, and you are using it as a procedure. Try this:

t:= exp(2*Pi*I/11);
Mij:= (i,j)-> M[(i mod 11)+1, (j mod 11)+1] ;  
mu:= proc(i,j)
local n,m,k;
     add(add(add(a[k]*a[m]*a[n]*t^m*Mij(i+k-m,j+n-m), n= 0..10), m= 0..10), k= 0..10)
end proc;

Your "New problem" is caused by you trying to return an expression sequence. There is no facility for the return value of a procedure produced by unapply to be an expression sequence. There are two things you can do: (1) Make the return value a list, or (2) Make the return value a list and compose the result with op to convert it back to an expression sequence.

To do (1):

f:= unapply(
      [seq(product(t[j]^'Q[j,i]',j=1..RowDimension(Q)),i=1..ColumnDimension(Q))]
    , seq(t[i],i=1..RowDimension(Q))
);

To do (2):

f:= op@unapply(
      [seq(product(t[j]^'Q[j,i]',j=1..RowDimension(Q)),i=1..ColumnDimension(Q))]
    , seq(t[i],i=1..RowDimension(Q))
);

The solve command should contain variables u and v, not %u and %v.

You can do it like this:

for i in seq(0..100, 0.2), seq(100..0, -0.2) do ... end do;

I will assume that the backslash in your expression should have been a forward slash---that it represents ordinary division. I'll plot a unit sphere in spherical coordinates. So, I am also assuming that you want x and y to range from -1 to 1.

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

plot3d(
     1, theta= 0..2*Pi, phi= 0..Pi,
     color= f(cos(theta)*sin(phi), sin(theta)*sin(phi)),
     coords= spherical, style= patchnogrid, labels= [x,y,z]
);

 

Make it a single command:

eval(y, isolate(x, D(a)));

Do you want a uniform random selection from all 6-tuples of nonnegative integers whose sum is 8? It can be done like this:

C:= combinat:-composition(8+6, 6):
C[(rand() mod nops(C))+1] -~ 1;

If you want to make such a random selection repeatedly, the above can be made more efficient. Let me know.

Your attempt to trap division-by-zero errors went awry. You set it up so that division by zero returns infinity, but the plots:-circle command doesn't know what to do with infinity as an argument. Your problem can solved by simply filtering out the values that lead to division by zero; there is no need to trap those errors. 

To fix the problem, simply replace the line

d := seq(circle([1, 1/i], 1/i, color = blue), i = -20 .. 20, .1);

with

d:= seq(`if`(i=0, NULL, circle([1, 1/i], 1/i, color= blue)), i= -20 .. 20, .1):

The principles for solving the system of piecewise ODEs are the same as the simplified example above. It is done like this:

Sys1:= EQ||(1..3), op(2, EQ4), op(2, EQ5):
Sys2:= EQ||(1..3), op(4, EQ4), op(4, EQ5):
ICs1:= seq(q||k(0)=0, k= 1..5), seq(D(q||k)(0)=0, k= 1..3):
Sol1:= dsolve({Sys1, ICs1}, numeric, maxfun=0, range= 0..10):
ICs2:= eval(
     [seq(q||k(10) = q||k(t), k= 1..5),
      seq(D(q||k)(10) = diff(q||k(t), t), k= 1..3)
     ], Sol1(10)
)[]:
Sol2:= dsolve({Sys2, ICs2}, numeric, maxfun= 0):
P1:= plots:-odeplot(Sol1, [seq([t, q||k(t)], k= 1..5)], t= 0..10):
P2:= plots:-odeplot(Sol2, [seq([t, q||k(t)], k= 1..5)], t= 10..20):
plots:-display([P1,P2]);

The solution to this ODE becomes singular before t = 0.03. However, I will show how to work with an ODE like this using the function f(x,t) from your earlier post. That one doesn't go singular until about t = 15.


restart:

f:= (x,t)-> piecewise(t < 10, (1-t)*sin(Pi*x), 10 < t, 0):

f(x,t);

piecewise(t < 10, (1-t)*sin(Pi*x), 10 < t, 0)

eq1:= diff(y(t),t$2) - y(t)^2 - f(x,t) = 0:

eq2:= simplify(int(lhs(eq1)*sin(Pi*x), x= 0..1));

eq2 := piecewise(t < 10, (1/2)*(t*Pi-4*y(t)^2-Pi+4*(diff(y(t), t, t)))/Pi, 10 <= t, (2*(diff(y(t), t, t)-y(t)^2))/Pi)

To set up the arguments to dsolve, you need to know the operand positions within the piecewise expression. The upper branch is operand 2 and the lower branch is operand 4.

lprint(%);

piecewise(t < 10, (1/2)*(t*Pi-4*y(t)^2-Pi+4*(diff(diff(y(t), t), t)))/Pi, 10 <= t, 2*(diff(diff(y(t), t), t)-y(t)^2)/Pi)

We call dsolve twice: once for 0 <= t <= 10 and once for t > 10.

Sol1:= dsolve({op(2, eq2), y(0)=0, D(y)(0)=0}, numeric):

We use that solution to get new initial conditions for t = 10.

Sol2:= dsolve({op(4, eq2), eval({y(10) = y(t), D(y)(10) = diff(y(t), t)}, Sol1(10))[]}, numeric):

P1:= plots:-odeplot(Sol1, [t, y(t)], t= 0..10):

P2:= plots:-odeplot(Sol2, [t, y(t)], t= 10..13):

plots:-display([P1,P2]);

 

``

 

First 295 296 297 298 299 300 301 Last Page 297 of 395