Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

The Explore command seems to not work directly with matrices. I get around this using a procedure M to access the matrix.

M:= (i,j)-> m[i,j]:
Explore(
   plots:-pointplot([seq([M(a,k), .1*k], k= 1..op([1,2], m))]), 
   parameters= [a= 1..op([1,1], m)]
); 

 

The domain is given as (x,t) in (-infinity, infinity). Since that interval is given with rounded brackets () rather than square brackets [], the endpoints are not included. Thus, there's no need for you to be able to evaluate your function at infinity.


 

restart:

The following fsolve technique works because one equation is linear and the other polynomial. The linear equation is used to eliminate a variable, then fsolve will return all real roots for a univariate polynomial.

P1:= y^2 = x^3+x^2:
P2:= y = 2*x+1:
Sys:= (lhs-rhs)~({P1,P2}); #Put into equal-to-zero form.
V:= [indets(Sys, name)[]];
E:= eliminate({P1,P2}, V[2]);
#Could've just as well eliminated V[1] above.
map2(eval, eval(V, E[1]), [fsolve(E[2])]);

{y-2*x-1, -x^3-x^2+y^2}

 

[x, y]

 

[{x = (1/2)*y-1/2}, {y^3-9*y^2-y+1}]

 

[[-.6920214716, -.3840429433], [-.3568958679, .2862082642], [4.048917340, 9.097834679]]

(1)

Here's another (easier) way to find all roots for a polynomial system. This one doesn't rely on being able to eliminate a variable.

RootFinding:-Isolate(Sys, V);

[[x = -.6920214716, y = -.3840429433], [x = -.3568958679, y = .2862082642], [x = 4.048917340, y = 9.097834679]]

(2)

Here's another way to plot systems of bivariate polynomials.

algcurves:-plot_real_curve(mul(Sys), V[], gridlines= false);

 

The great thing about plot_real_curve is that it automatically figures out how big to make the viewing window to capture all the intersections.

 

``


 

Download BivarPoly.mw

No, there's no such library command, but it's trivial to write one. It took me two minutes and nine lines of code.

Okay, I fixed it. The problem is the line

F:= (q,x,alpha)-> expand(eval(u, Solu[1]));

This needs to be changed to

F:= unapply(eval(u, Solu[1]), q, x, alpha);

Then you need to remove the assignment to alpha at the beginning of the worksheet and change the colon after the plot command to a semicolon. That's all there is to it!

Because I find it awkward to use a preposition as an adjective, especially for nonnative English users, I use the equivalent terms surjective for "onto",  injective for "one-to-one", and bijective for "one-to-one and onto". If F is a function from finite set A to finite set B given by a procedure F, then the following checks whether it's surjective and/or injective:

Bijective:= (F, A::set, B::set)->
   (FA->
      if FA subset B then 
         'surjective' = evalb(FA = B),
         'injective' = evalb(nops(FA) = nops(A))
      else 
         error "The codomain B is inappropriate"
      end if
   )(F~(A))
:

Examples:

F:= x-> 2*x:
A:= {1,2,3,4,5}:
B:= {2,4,6,8,10}:
Bijective(F, A, B);

     surjective = true, injective = true

A:= {a, b, c, d, e}:
P:= combinat:-randperm(A);

     P:= [a, e, b, c, d]

F:= proc(x) local p; member(x,A,p); P[p] end proc:
Bijective(F, A, A);

     surjective = true, injective = true

Suppose that you have a function Phi(s) whose second derivative is phi(s). Then substitute its second derivative for phi(s) in your original expr:

restart:
expr:= (k*s^2+1)*diff(phi(s),s$2)-k*phi(s)+s*k*diff(phi(s),s):
expr2:= int(int(eval(expr, phi(s)= diff(Phi(s),s$2)), s), s);

(I don't know why things come out so large when I copy-and-paste Maple output. Does anyone know how to control that?)

 

 

The laplace command is in the inttrans (INTegral TRANSforms) package, so you need to use a package-name prefix or a with(inttrans) command:

inttrans:-laplace(exp(3*t)*cos(2*t), t, s);

Considering that you're using Maple 13, inttrans:-laplace may need to be changed to inttrans[laplace], which'll also work in newer Maple.

Let's say that the matrices are named A and B. In the first worksheet, do

save A, B, "MyFile.m":

The MyFile can be anything, but the extension should probably be .m if the matrices are large, as that causes an encoding into a Maple-specific format. In the second worksheet, do

read "Myfile.m": 

At this point, the names A and B will be defined in the second worksheet to whatever they were in the first worksheet at the time of the save.

Because of the special evaluation rules of seq, add, and mul, you have to do

eval((f@Seq)(i, i= 1..2), Seq= seq);

and likewise for the add. The Seq here is just a dummy; it could be any name. And note that i does not get the usual protection against global interference that those special evaluation rules provide.

Here's a completely different method based on the relation being given by a boolean procedure of two arguments rather than by a set of ordered pairs. That is, for x, y in S, R(x,y) must return true if x is related to y and false otherwise.

Matrix methods are used to check symmetry and transitivity.

EqvRel:= (R::procedure, S::set)->
   ((A::Matrix)->
      (
         'reflexive' = andmap(x-> R(x,x), S),
         'symmetric' = ArrayTools:-IsZero(A - A^+),
         'transitive' = ArrayTools:-IsZero(A - signum~(A^2 + A))
      )
   )
   (Matrix(nops(S)$2, (i,j)-> `if`(R(S[i],S[j]), 1, 0), datatype= integer))
:

Examples:

Rel1:= (x,y)-> irem(x-y, 3) = 0:
S:= {'rand()' $ 30}:

EqvRel(Rel1, S);

     reflexive = true, symmetric = true, transitive = true

Rel2:= (x,y)-> x <= y:
EqvRel(Rel2, S);

     reflexive = true, symmetric = false, transitive = true

Rel3:= (x,y)-> x <> y:
EqvRel(Rel3, S);

    reflexive = false, symmetric = true, transitive = false

 

Your input array([1 1 1 2]) needs to be array([1,1,1,2]). Commas are always needed as separators on input.

The option maxmesh only applies to BVPs; this is an IVP.

The problem is that alias only creates rather-superficial pointers. They are intended mostly to de-clutter the display of expressions. They don't work programatically. In other words, in the following commands, diff never sees the alias A, it only sees f(x):

alias(A=f(x)):
diff(A^2, A);

Error, invalid input: diff received f(x), which is not valid for its 2nd argument
 

You can create more-substantial pointers with freeze, and dereference them with thaw:

restart:
A:= freeze(f(x)):
thaw(diff(A^2, A));
    
2*f(x)

If you also want to use an alias for f(x) so that you never see it in output because you consider it private, that'd work fine.

You mentioned pointers to vectors. I don't see any vectors in your code. You also load LinearAlgebra, but you don't use anything from that package.

Here is a solution for the first problem. I solve the ODE as a parametrized IVP with parameter e and then fsolve for some values of e such that the right-side boundary condition is satisfied. You'll need to try some fiddling around with fsolve's options to get more values. Please let me know if there are any details below that you can't figure out.

Update: See a Reply below for vastly improved version of this worksheet where I show how to fsolve for all the eigenvalues in a given interval.

restart:

#Name the boundary points and boundary values:
(A, B, psiA, psiB, DpsiA):= (0, 3.5, 1, 0, 0):

ode:= diff(psi(u), u$2) = 2*(u^4 - e)*psi(u):

Sol:= dsolve(
   {ode, psi(A) = psiA, D(psi)(A) = DpsiA},
   numeric, parameters= [e]
):

#A procedure for fsolve to find zeros for:
F:= proc(e)
   Sol(parameters= [:-e= e]);
   eval(psi(u), Sol(B)) - psiB
end proc:

E:= table():
E[1]:= fsolve(F);

.6679862422

(1)

E[2]:= fsolve(F, E[1]..infinity);

10.24430877

(2)

#By changing the range given to fsolve, you may get more eigenvalues.
#There are also a few other ways to guide fsolve towards or away from
#various solutions. See ?fsolve,details.

#Now, plot all found solutions.

E:= convert(E, list):

(m,M):= (min,max)(E): #Only needed to color the plots

PL:= table():
for e_k in E do
   Sol(parameters= [e= e_k]);
   PL[e_k]:= plots:-odeplot(
      Sol, [u, psi(u)], u= A..B,
      legend= [e= evalf[3](e_k)],
      color= COLOR(HUE, .8*(e_k - m)/(M - m))
   )
end do:

plots:-display(
   convert(PL, list), gridlines= false, size= [1000,1000],
   legendstyle= [font= [TIMES,24]],
   thickness= 3,
   title= "Solution curves for all eigenvalues found",
   caption= typeset("\n", e, " is the eigenvalue"),
   titlefont= [TIMES,32], axesfont= [TIMES,16],
   labelfont= [TIMES,32], captionfont= [TIMES,24]
);

 

 


 

Download ShootingForEigenvalues.mw

Every closed hyperrectangle (henceforth: rectangle) in R^d with edges parallel to the coordinate axes can be uniquely specifed by what I'll call its principal diagonal, which is the unique diagonal with endpoints A and B such A[i] < B[i] for i= 1..d. A rectangle is to be divided into N^d congruent subrectangles. These can be indexed by i, 0 <= i < N^d. The following procedure returns the ith subrectangle:

alpha:= (N::posint, d::posint)-> 
   (i::nonnegint)-> convert(N^d+i, 'base', N)[..d]
:
Subrectangle:= proc(i::nonnegint, R::Rectangle(list,list), N::posint)
local A:= op(1,R), Alpha:= alpha(N,nops(A))(i), v, a;
   v:= (op(2,R) -~ A)/~N;
   a:= A +~ Alpha*~v;
   'Rectangle'(a, a +~ v)
end proc:

Subrectangle(5, Rectangle([0,0,0], [1,1,1]), 3);
    
Rectangle([2/3, 1/3, 0], [1, 2/3, 1/3])

First 184 185 186 187 188 189 190 Last Page 186 of 395