Carl Love

Carl Love

28095 Reputation

25 Badges

13 years, 101 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

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

 

``

 

Individual variables can be cleared with unassign.

This may not be the most efficient way, but I think that it is robust and that it handles all the special cases.

power:= (term,x)-> `if`(term=0, undefined, expand(diff(term,x)*x/term));

 

Use piecewise:

f:= t-> piecewise(t < 10, 1-t, t):

f(t);

You have not defined the function for t <= 0 or t = 10. The above will of course apply the upper branch 1-t to t <= 0 and the lower branch to t = 10.

Try this, if you haven't already:

for T from 0 to 15 by 0.1 do
    
your script
end do;

If that doesn't work, then you'll need to post your code.

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