Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

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

One possible such command is codegen[cost], but in this case the exponentiations (with small integer exponents) would be counted as an appropriate number of multiplications, because that's how the expression would be numerically evaluated.

There's no need to use arrow expressions; they just complicate things in this case. The following code does what you want. It works for any number of input expressions. It doesn't rely on any specific names being used such as x, y, or t.

linearise:= proc(S::list(algebraic), P::list(anyfunc(name)=algebraic))
local F:= lhs~(P), t:= op~({F[]})[];
   if nops([t]) > 1 then 
      error "Expected exactly 1 independent variable but received", t
   end if;
   diff~(F,t) =~ thaw(map(mtaylor, subs(F=~ freeze~(F), [S,P])[], 2))
end proc:

#Example usage
a:= x(t)*(y(t)-1);
b:= 4 - y(t)^2 - x(t)^2;
linearise([a,b], [x(t)= 0, y(t)= -2]);

 

Here's another procedure. This'll work in any number of dimensions, as long as the hyperfaces are parallel to the coordinate hyperplanes.

Vertices:= proc(P::list, Q::list) 
local x,p;
   seq([seq(x, x= p)], p= Iterator:-CartesianProduct(zip(`[]`,P,Q)[]))
end proc:

Vertices([1,1,2], [3,4,5]);

I don't know whether it can be done with geom3d.

I suggest that you stop using ancient and deprecated stats package and instead use the newer Statistics package. Then

x:= Statistics:-Sample(Uniform(0,1), 10);
add(x)^a;

Since the above is hardly worth doing, I think that what you actually want is

add(x_i^a, x_i= x);

Right-click on the Matrix or Vector output and select Browse.

The following does exactly what you're trying to do using a different ODE (because you didn't supply yours) and using a list of three operators as the first argument to plot3d. Because of the option remember, td is only called once (instead of three times) for each mesh point of the plot.

ans:= dsolve({diff(y(t),t$2)=y(t), y(0)=a, D(y)(0)=0}, numeric, parameters= [a]):
td:= proc(x,tt)
option remember;
   ans(parameters= [a= x]);
   eval([t, y(t), diff(y(t),t)], ans(tt))
end proc:

TD:= (k::{1,2,3})-> (x,tt)-> td(x,tt)[k]:
plot3d(TD~([1,2,3]), 0..3, 0..3, labels= [t, y, `y'`]);

 

In Maple, several binary infix operators {=, <, .., ^, ::, etc.} always have exactly two operands. For =, each of the operands can be anything---including NULL, a sequence, or another equation---as long as it's enclosed in parentheses. So (A = B) = C and A = (B = C) are both allowed. I realize that the display of the parentheses in printed output is not ideal.

This is implemented in the kernel, so it works regardless of which GUI (Standard, Classic, command-line) or GUI mode (document, extended typesetting, etc.) you use.

P:= proc(u::{function, indexed}, shift::anything:= 1)
local pos:= `if`(procname::indexed(posint), op(procname), 1);
   subsop(pos= op(pos, u) + shift, u)
end proc:

P[1](u(i,j));
                          u(i + 1, j)
P[2](u[i,j,k], 3);
                          u[i, j + 3, k]

This allows you to have a single operator that does it all. It doesn't care whether you've used square brackets or parentheses. It doesn't care how many indices there are. And you can change the shift amount from the default of 1,

 

This can be prevented by using forget(fsolve) or gc() between the fsolves. An automatically occuring garbage collection would also clear the cache. Anytime that you see the status bar update, there's been a garbage collection.

Another approach is to simply use fsolve(f) in both cases. This'll work with or without quotes.

Yes, the problem is likely high memory usage due to large symbolic expressions. We call it expression swell. A direct symbolic solution is not easily amenable to distributed (multi-core) processing. Nor is any memory-bound process a good candidate for multi-core: Distributed processing increases memory usage significantly (which isn't a problem if the process is distributed over a network of computers).

Depending on the complexity of your symbolic coefficients, it may be possible to interpolate an exact symbolic solution from exact numeric solutions of the system numerically evaluated at numerous values of the parameters. This technique would be amenable to distributed processing. But first think about whether it's worth doing vis-a-vis my Reply above.

plot([seq([i, eval(u[i,20], Sol[])], i= 1..25)], style= point);

You can change the symbol used for the points, their size (symbolsize), and their color:

plot(
   [seq([i, eval(u[i,20], Sol[])], i= 1..25)],
   style= point, symbol= solidcircle, symbolsize= 16, color= red
);

 

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