Carl Love

Carl Love

28150 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

Without going into much detail, I see that your final plot command fails because there is no numeric value for q. Is your q supposed to have a value?

@mapleatha Sorry, I misread your Question. I thought that you were getting unevaluated output and the blue was what you were expecting. My fault, totally. This Answer can just be ignored.

Is the domain of the function a finite set?

@kfli For some reason that I can't figure out, the freeze command is intentionally "crippled" to not work on names such as x[n]. This crippling is obvious in the very brief code that you can see via showstat(freeze). But it will work on x(n), which is considered a  function rather than a name. So try changing all x[n] to x(n). If you want these to display as subscripted, that can still be done. You can freeze a whole batch of expressions in a single command in a variety of ways. One example is

assign(seq(x(k)= freeze(y(k)), k= 1..9));

Let me know how that works for you.

@ecterrab I think that your impression that the OP is trying to differentiate wrt a function may be based on my example rather than on the OP's code. I just used that example because I didn't have the patience to decipher the OP's convoluted alias commands.

@macmp91 I think that you may only be looking at the eigenvalues when they are correct. In procedure Fn, immediately after the sort command, put the command

print(D[1]);

Then run the code until it errors out. Immediately before the error, I believe that you'll see the negative eigenvalue. When the sqrt is applied to this number, it becomes the imaginary value which causes the error message.

@macmp91 You should check for negative eigenvalues in procedure Fn. Do they make sense for this problem? If not, then you need to adjust something. Perhaps the input to Fn is not realistic. It is the negative eigenvalues that are causing the error message. Perhaps you intended to use singular values rather than eigenvalues. (The singular values of A are the square roots of the eigenvalues of A.A^+ and are guaranteed to be nonnegative.) See ?SingularValues. The main floating-point algorithm computes them without first computing the eigenvalues, which is more robust.

Actually sin(t)^p and (sin(t))^p  and even (sin^p)(t) mean the same thing in Maple. Personally, I prefer the form with the fewest parentheses. The operator binding between f and (x) in the Maple expression f(x) has the highest precedence and never requires extra parentheses. (But when using 2D Input, make sure not to put a space between f and (x).)

The famous mathematical constant Pi is capitalized in Maple; lowercase pi is just a variable.

Would you please attach a Maple worksheet showing the situation where you obtained a result containing Float(infinity)? You can use the green uparrow on the toolbar of the MaplePrimes editor to upload worksheets.

Often such a result comes because the answer to the problem is truly infinity. And often it comes due to round-off error causing division by a very small number. Usually we can determine which is the situation, and often the latter case can be corrected.

@acer I agree with Acer 100% on this. And I'll add that even if applyrule correctly did everything that it was supposed to do, it'd still be a fairly weak command compared to evalindets or subsindets.

@markweitzman 

Using the same technique that I used for the first problem, here are all the eigenvalues under 15 with plots of their solution curves. Note that I changed your piecewise to an equivalent Heaviside out of personal preference. I forgot to change "under 100" to "under 15" in the title (only) of the final plot
 

> 

restart:

> 

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

> 

ode:= diff(psi(u), u$2) = (2*Pi)^2*(Heaviside(u-1) - e)*psi(u):
ic:= psi(A) = psiA, D(psi)(A) = DpsiA:

> 

Sol:= dsolve({ode, ic}, numeric, parameters= [e], abserr= 1e-13):

> 

#The characteristic function:
F:= proc(ee)
   Sol(parameters= [e= ee]);
   eval(psi(u), Sol(B)) - psiB
end proc:

> 

#This plot will guide us to the eigenvalues, which are its zeros.
plot(
   F, 0.1..15, numpoints= 999, view= [DEFAULT, -0.5..0.5],
   thickness= 2, size= [2000,500], color= orange, xtickmarks= 60,
   title= typeset("Zeros of characteristic function for ", ode),
   titlefont= [TIMES,24], gridlines= false,
   labels= [e, ``], labelfont= [TIMES,24]
);

 
> 

#Candidate intervals for eigenvalues, based on the plot:
EI:= [0..0.25, 0.7..0.74, 1..1.25, 1.5..1.75, 2..2.5, 2.75..3, 3.5..3.75, 4.25..4.75, 5.5..5.75, 6.5..7, 8..8.25,
   9.25..9.75, 10.75..11.25, 12.5..13, 14.25..14.75]:

> 

Digits:= 7:
E:= table():
for ei in EI do
   r:= fsolve(F, ei, fulldigits);
   if r::numeric then
      E[ei]:= r
   else
      printf("Failed to find the eigenvalue known to be in %a\n", ei)
   end if
end do:

> 

#The found eigenvalues are
E:= sort(convert(E, list));

[.1843580, .7074703, 1.206517, 1.562500, 2.084468, 2.800468, 3.560780, 4.535382, 5.557413, 6.775081, 8.057593, 9.518408, 11.05834, 12.76398, 14.55906]

(1)
> 

#Plot the corresponding solutions.
(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, numpoints= 999,
      legend= [e= evalf[3](e_k)],
      color= COLOR(HUE, .8*(e_k - m)/(M - m))
   )
end do:

plots:-display(
   [entries(PL, 'indexorder', 'nolist')], gridlines= false, size= [1000,1000],
   legendstyle= [font= [TIMES,24]],
   thickness= 2,
   title= typeset("Solution curves for all eigenvalues under 15 for ", ode),
   caption= typeset("\n", e, " is the eigenvalue; hues are scaled linearly by ", e, "."),
   titlefont= [TIMES,16], axesfont= [TIMES,16],
   labelfont= [TIMES,32], captionfont= [TIMES,16]
);

 
> 

 


 

Download ShootingForEigenvalues.mw

I think this may be handled by the Physics package, but I really don't know. So I updated your tags to include Physics so that someone who knows will notice this Question.

This is an updated version of the worksheet above. I show how to obtain (by the same shooting method) all the eigenvalues in an interval, and I do it and plot it for all under 100.

Note that these plots are much clearer and have more annotation when viewed in the worksheet than when they are viewed here on MaplePrimes.
 

> 

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):
ic:= psi(A) = psiA, D(psi)(A) = DpsiA:

> 

Sol:= dsolve({ode, ic}, numeric, parameters= [e]):

> 

#The characteristic function:
F:= proc(ee)
   Sol(parameters= [e= ee]);
   eval(psi(u), Sol(B)) - psiB
end proc:

> 

#This plot will guide us to the eigenvalues, which are its zeros.
plot(
   F, 0.1..100, view= [DEFAULT, -100..100],
   thickness= 2, size= [1000,100], color= orange,
   title= typeset("Zeros of characteristic function for ", ode),
   titlefont= [TIMES,24],
   labels= [e, ``], labelfont= [TIMES,24]
);

 
> 

#Candidate intervals for eigenvalues, based on the plot:
EI:= [0..2, 4..6, 10..12, 16..18, 22..25, 30..33, 39..41, 47..50, 56..59, 66..68, 76..78, 86..88, 96..98]:

> 

E:= table():
for ei in EI do
   r:= fsolve(F, ei);
   if r::numeric then
      E[ei]:= r
   else
      printf("Failed to find the eigenvalue known to be in %a\n", ei)
   end if
end do:

> 

#The found eigenvalues are
E:= sort(convert(E, list));

[.6679862422, 4.696795558, 10.24430877, 16.71189010, 23.88999426, 31.65945727, 39.94141775, 48.67906755, 57.82916534, 67.35751908, 77.23651840, 87.44459180, 97.96981713]

(1)
> 

#Plot the corresponding solutions.
(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, numpoints= 999,
      legend= [e= evalf[3](e_k)],
      color= COLOR(HUE, .8*(e_k - m)/(M - m))
   )
end do:

plots:-display(
   [entries(PL, 'indexorder', 'nolist')], gridlines= false, size= [1000,1000],
   legendstyle= [font= [TIMES,24]],
   thickness= 2,
   title= typeset("Solution curves for all eigenvalues under 100 for ", ode),
   caption= typeset("\n", e, " is the eigenvalue; hues are scaled linearly by ", e, "."),
   titlefont= [TIMES,16], axesfont= [TIMES,16],
   labelfont= [TIMES,32], captionfont= [TIMES,16]
);

 
> 

 


 

Download ShootingForEigenvalues.mw

@markweitzman

The name e is used for two variables in the scope of procedure F: It is a global used in the ODE, and it is the procedure parameter of F. These are two different variables that just happen to have the same name. In such situations, the global variable can be distinguished by using the prefix :-. I could just as well have used a different name for the procedure parameter, like ee. Then the statement could be Sol(parameters= [e= ee]), or Sol(parameters= [:-e= ee], or as you pointed out simply Sol(parameters= [ee]), (but not then Sol(parameters= [e])).

The algorithms for solving IVPs and BVPs are very different. As Mariusz's Answer shows, the BVP needs to be solved separately with a different approxsoln for each eigenvalue. On the other hand, the IVP only needs a single call to dsolve from which all the eigenvalues in any interval can be obtained. In a Reply below, I've updated the worksheet above, and I show how to obtain all the eigenvalues in an interval, and I actually do it and plot it for all under 100.

 

@Mariusz Iwaniuk For numeric BVPs, dsolve allows parameters in exchange for extra BCs. The BCs are counted at the syntax level, and it won't let you get away with giving the wrong number of them (even if perchance the solution satisfies an extra condition).

First 349 350 351 352 353 354 355 Last Page 351 of 711