Carl Love

Carl Love

28025 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Short answer (suitable if you have very little understanding of Maple internal structures):

The command

P_eqnlist:= ((rhs=lhs)@`=`@op)~(op(P)[-1]) 

will return that list of equations as a Maple list. If you want treat that list (or any list) as an "array" (in the colloquial sense), nothing further is needed. For example, P_eqnlist[3] will return the 3rd equation in the list. If you want an Array (in the formal Maple sense), do

P_eqnarray:= convert(P_eqnlist, Array).

 

Longer answer (suitable if you have a modicum of knowledge of Maple internal structures):

When working in the usual worksheet mode, most results returned by DifferentialGeometry are displayed on screen in a form somewhat different than their internal structure. The command lprint can be applied to any Maple output as a first step towards revealing its internal structure. This command is like print and printf in that it does not produce true output itself; rather it just causes information to be shown on your screen (in the most primitive plaintext form). There are many commands for deeper probing of internal structures; however, in this case, lprint was all that I needed to use to understand what was going on.

The command op (short for operand) is a primitive command used to take apart structures. The lprint(P) reveals that the output of Prolong is a function (in the formal Maple sense of that word) named _DG. That function has a single argument---a list---as revealed by its [...]. That argument is extracted with op(P). The last member of that list has the equations that we want (although they are seen to not be actually stored as equations---we need to do a little rearranging). Negative indices (such as my [-1]) are used extract list entries counting from the right (i.e., from the back end). The extracted entry is itself a list---a list of lists of pairs. 

Next, I used a composed operator ((rhs=lhs)@`=`@op)~: Breaking this down from right to left:

  • The forces the operation to be done elementwise over the list rather than operating on the list as a single entity.
  • The op takes a list (such as [x,y]) and returns the "naked" entries, (x,y), i.e., without the list wrapping.
  • The @s are operator-composing operators. In other words, if h:= f@g, then h(x) = f(g(x)) for all x.
  • The `=` forms the pair (x,y) into the equation x=y. The quotes are required when using an operator that ordinarily has special syntax (is ordinarily infix) as if it were just a name.
  • The (rhs=lhs) rearranges that to y=x. (It stands for right-hand side equals left-hand side.) This is itself an operator composed of the operators rhs=, and lhs.

 

Even more details (if you want to know how structures are intentionally obscured):

function (in the somewhat idiosyncratic Maple-specific sense) is simply a name followed by some arguments in parentheses. In input code, it looks just like a procedure call; however, it survives to the output stage either because there is no such procedure or the procedure decided to return a specific call unevaluated. Because function and procedure are often used interchangeably in computer literature (even somewhat in Maple documentation), what I've defined above is often called an unevaluated function or unevaluated function call. But in Maple code, it's just type function, and it's distinct from type procedure.

Prettyprinting refers to the process by which plaintext structures (which are essentially one-dimensional) are represented in higher-dimensional and more-familiar-to-human-readers forms. The extent to which it's used can be controlled by the interface command settings prettyprint and typesetting (see ?interface). The lprint command simply displays its arguments without prettyprinting (equivalent to setting interface(prettyprint= 0)). If there is a procedure named `print/F`, then it will control the prettyprinting of any function with name F. In the case at hand, the function returned by Prolong has name _DG and there is a procedure `print/_DG`. That procedure (intentionally) only displays a small portion of the information contained in the function.

Simply include the option 'params'= {n} in the dchange command. (This is clearly and prominently stated (in my opinion) on the help page; but I'm not saying that to chastise you.)

And although using subs doesn't cause a problem in this particular case, I strongly advise you to use eval(%, n= 2) instead. One reason is that eval won't substitute a numeric value for the bound (or with-respect-to) variable of a derivative, which would be nonsense mathematically. On the other hand, subs doesn't care at all about such mathematical subtleties.

The uncertainty of decimal computations is nowhere near as bad as Kitonum's Answer leads you to believe. By using the range arithmetic (or interval arithmetic) commands shake and evalr, you can get 100%-confidence intervals for the computed results. To obtain results accurate "to the penny", gradually increase Digits until the interval's width is less than 0.005. It turns out in this case that Digits = 12 is sufficient.

restart:
A:= P*(1+r/n)^(t*n): #symbolic formula 
(P, n, t):= (15000, 365, 10): #the exact input values
#the decimal input values: note that I use a different name than r:
r0:= 0.06: 
e:= 0.005: #half a cent: maximal error tolerance
for Digits from Digits do 
   CI:= op(evalr(eval(A, r= shake(r0))));
   if rhs(CI) - lhs(CI) < e then break fi
od:
printf("Using Digits:= %d, the result is in the interval %a.", Digits, CI);
Using Digits:= 12, the result is in the interval 27330.4341541 .. 27330.4351515.

Since 12-digit arithemtic is required to get 7 correct digits (which includes the 5 before the decimal point), we say that the computation requires 12 - 7 = 5 guard digits.

Your F is a procedure parameter, not really a variable. Since is passed an expression, x^2 + y^2 + z^2, and not a name, you can't assign to it. The solution is to begin the procedure by copying to a local variable, which is then used instead of F throughout.

Assuming that E means the volume enclosed by the ellipsoid[*1] from your related plotting Question, the integral can be easily done using the same coordinate transformation. This is probably not worthwhile doing if the goal is simply to get the integral. But given that you want both the plot and the integral, it becomes more worthwhile.
 

restart
:

interface(rtablesize= 10): #kludge to get MaplePrimes to display M2019 worksheet (Ignore this line.)
:

CV:= [x, y, z]: #old (Cartesian) coordinate names
V:= [rho, theta, phi]: #new coordinate names
P:= [a, b, c]: #parameters: semi-axes of ellipsoid (in x,y,z order)
:

#Get pre-defined spherical coordinates transform so that we can modify it:
Sph:= changecoords(CV, CV, 'spherical', V);

[rho*sin(phi)*cos(theta), rho*sin(phi)*sin(theta), rho*cos(phi)]

#inverse transformation from (ellipsoidal to Cartesian):
T:= P *~ Sph:
addcoords('ELL', V, T, P); #Add parameterized coordinate system named ELL.
:

#numeric values specific to this exercise:
Pvals:= (1,2,3): #specific semi-axes
R:= V=~ [0..1, -Pi..Pi, 0..Pi]: #coordinate ranges (for full ellipsoid)
:

#All the above code is same as for the plot of the ellipsoid.

#Now, code specific to the integral:

 

#assumptions for simplifying transformed expressions
#(These aren't necessary for this particular problem.):
A:= (lhs~(R) in~ (RealRange@op@rhs)~(R))[], (P >~ 0)[];

`in`(rho, RealRange(0, 1)), `in`(theta, RealRange(-Pi, Pi)), `in`(phi, RealRange(0, Pi)), 0 < a, 0 < b, 0 < c

#Compute the integration differential of the transformation:
(jac,det):= VectorCalculus:-Jacobian(<T[]>, V, 'determinant'):
det:= abs(simplify(det)) assuming A;
unassign('jac'); #We only need that determinant; the matrix can be discarded.

sin(phi)*a*b*c*rho^2

f:= exp(-add(CV^~2/~P^~2)); #the integrand in Cartesian coordinates

exp(-x^2/a^2-y^2/b^2-z^2/c^2)

#the desired integral in the new coordinates:
J:= simplify(Int(changecoords(f, CV, ELL(P[]), V)*det, R)) assuming A;

Int(exp(-rho^2)*sin(phi)*a*b*c*rho^2, [rho = 0 .. 1, theta = -Pi .. Pi, phi = 0 .. Pi])

value(J) assuming A;

4*a*b*c*(-(1/2)*exp(-1)+(1/4)*Pi^(1/2)*erf(1))*Pi

eval(%, P=~ Pvals);

24*(-(1/2)*exp(-1)+(1/4)*Pi^(1/2)*erf(1))*Pi

evalf(%);

14.28587832

 


 

Download EllipsoidalCoords.mw

[*1]The volume enclosed by the ellipsoid is not quite the same thing as the ellipsoid itself, so using the name E for both can be confusing.

Here is how to do the plot by adjusting Maple's pre-defined spherical coordinates. This is a good, clean, way to do this, and it also facilitates subsequent integration over the region plotted. Also, your reposted version of this Question made it clear that this was your instructor's intention.

restart:
CV:= [x, y, z]: #old (Cartesian) coordinate names
V:= [rho, theta, phi]: #new coordinate names
P:= [a, b, c]: #parameters: semi-axes of ellipsoid

#Get pre-defined spherical coordinates transform so that we can modify it:
Sph:= changecoords(CV, CV, spherical, V);
   Sph := [rho*sin(phi)*cos(theta), rho*sin(phi)*sin(theta), rho*cos(phi)]
#inverse transformation (ellipsoidal to Cartesian):
T:= P *~ Sph:
addcoords(ELL, V, T, P); #Add parameterized coordinate system named ELL.

#numeric values specific to this exercise:
Pvals:= (1,2,3): #specific semi-axes (in x,y,z order)
R:= V=~ [0..1, -Pi..Pi, 0..Pi]: #coordinate ranges
 
plot3d(
   eval(V, rho= rhs(eval(rho, R))), ([theta, phi]=~ eval([theta, phi], R))[],
   coords= ELL(Pvals), scaling= constrained, labels= CV
);

Maple does have a pre-defined coordinate system named ellipsoidal; however, it doesn't seem suited to this problem, and it's certainly not a variation on spherical.

The error message suggests an obvious thing to try. Change your LPSolve command from

LPSolve(your arguments)

to

LPSolve(your arguments, depthlimit= n)

where n is some positive integer greater than 263.

I'm not saying that this will work, but it should be tried, if the execution time is reasonable.

 

If the number displays as 0., then your computation has (inadvertently) rounded it down to exactly 0, and there's no "hidden" digits left. You may (I emphasize, may) be able to correct this simply by setting Digits to a higher value. Here's a trivial (although fundamental) example:

restart:
Digits:= 10: #its default value
eps:= evalf(10^(-10));
                                         -10
                    eps := 1.000000000 10   

#The evalf below is not ordibarily necessary; it's only to facilitate this example
#(see footnote).
evalf(1. + eps) - 1.; 
                               0.
restart:
Digits:= 20:
eps:= evalf(10^(-10)):
evalf(1. + eps) - 1.;
                                     -10
                       1.000000000 10   

However, it is usually better to re-arrange the order of operations to avoid such problems.[*1] These issues are very well-known and extensively studied in all computer languages that use floating-point numbers.

To understand these examples, as well as your original issue, you need to keep in mind that Digits affects all the subcomputations (both explicit and internal) that lead to your final result. Its effect goes much deeper than simply the rounding of the final result.

[*1]Note that in my example I used an otherwise-unnecessary call to evalf to change the order of operations to cause the erroneous rounding to 0..

Use procedure-form input for the ODE. Give the procedure option remember. When the integration is done, the indices of the table will contain precisely the values of the independent variable at which the ODE was evaluated. Here is the command to extract the list of indices, assuming that is your procedure of the ODE:

T:= [indices(op(4, eval(F)), 'nolist')];

No, not exactly, because that value depends on both the input lists and the model being fitted, particularly its number of fitted parameters, k, since n-k is the degrees of freedom. You can get the LinearFit  command to return the residual standard error like this:

#Create two random data lists, just for example:
(X,Y):= 'LinearAlgebra:-RandomVector(9)' $ 2:

#Fit two parameters, the usual intercept and slope:
L:= Statistics:-LinearFit([1, x], X, Y, x, output= solutionmodule):
L:-Results(residualstandarddeviation);
                        59.3362504084196

#Fit quadratic model (3 parameters) to the same data:
L:= Statistics:-LinearFit([1, x, x^2], X, Y, x, output= solutionmodule):
L:-Results(residualstandarddeviation);
                        50.7377653987838

The above shows that the value that you want isn't a function of X and Y alone. If you want to restrict attention to the case of just fitting a line, then a command to do it "on its own" could be easily constructed (it'd be a one-liner) from the above.

There is a Maple command dedicated to this type of computation: evala(Norm(...)).

evala(Norm(x - (-4+I)));
      x^2 + 8*x + 17

This command is much more general than complex conjugates. So, if the question were changed to "Let p(x) be an integer polynomial of degree 6 such that p(sqrt(2+sqrt(2))) = 0. Find a 4th-degree integer polynomial factor of p(x)."

evala(Norm(x - sqrt(2+sqrt(2))));
      x^4 - 4*x^2 + 2

Of course, you should also know how to do it Kitonum's way, and how to do it that way by hand.

I think that this is the generalization to vector-mode operations that you're asking about:

Suppose that ex is an algebraic expression[*1] with a single free variable[*2] x. To be concrete, I'll use

ex:= sin(x^2) + 3*x;

but it doesn't matter how complicated ex is nor how many separate commands were needed to build it. I can make a function (aka procedure or operator) named f equivalent to ex by binding[*3] x with the command unapply:

f:= unapply(ex, x);

Now, I want to specify a "list" or "vector" xVals of numeric values for x, let's say from 3 to 5 with 0.1 spacing:

xVals:= < seq(3..5, 0.1) >: 

Note the angle brackets <...>, which make it what Maple calls a Vector. You could just as well use square brackets [...], as you did above, which make it what Maple calls a list

Now I want to evaluate ex (using f) at every value in xVals and call that yVals. This part is amazingly easy, and it's the crux of what your Question is about:

yVals:= f~(xVals):

Note that there's no need to include the ~ symbol anywhere in the original expression. It's needed only one time for this process. So any algebraic expression can be made to operate on vectors without needing to edit the original expression. Also, there's no need to make an a priori definition of x as a vector.

The pairs can be plotted with

plot( < xVals | yVals >);

This is by no means the most-general generalization that can be made; there's many layers of generalization that could be put on top of this. Indeed, actually ex doesn't need to be an algebraic expression, and it can have any number of free variables. I only put those restrictions on as an aid to learning this material.

Definitions:

[*1]By algebraic expression, I mean any expression, possibly containing some free variables, such that if its free variables were given complex-number values, the expression would represent a single extended-complex number; and there exists some algorithm, at least in theory, for getting its decimal value at least to some finite number of decimal places.

In using the word algebraic, I don't mean to exclude transcendental functions, even non-elementary ones; but I do mean to exclude vectors, matrices, sets, lists, equations, inequations, etc., and expressions that evaluate to them -- anything that can't be evaluated to a single extended-complex number.

[*2]By free variable, I mean a variable in an expression which doesn't have an assigned value but which could be assigned a value such that the expression is still meaningful. So, note that being free is not an inherent property of the variable; it is determined with respect to an expression. A variable may be free in an expression and that expression embedded in a larger expression such that the variable is not free in the larger expression (example in next definition below).

[*3]Binding a variable means taking an expression with a free variable and embedding it in a larger context in which it is no longer free. As a nontrivial example, x^2+3*x is an expression with a free variable x. If I express (without evaluating) the indefinite integral with respect to x, as in Int(x^2 + 3*x, x), that's binding x (since x can no longer be meaningfully assigned a value before the integral is evaluated). Due to an unfortunate idiosyncracy of English, after its binding, a variable is called a bound variable, not a "binded" variable. 

Like this:

r0:= -4+I:
expand((x-r0)*(x-conjugate(r0)));

      

Note that rather than i is Maple's default symbol for sqrt(-1), though it can be changed to any symbol that you want.

While I strongly recommend that you learn the plot command recommended by MMcDara, as it is the most versatile such command, in this case the highly specialized FunctionPlot may be more suited to your purpose:

Student:-Calculus1:-FunctionPlot(3*x^3-2*x^2+5*x-7, x= -3..6);

And I don't mean to suggest that there's anything wrong with using plot for this! Indeed, I'd use plot if I were doing the problem myself; because I know all of its options, I'd annotate the plot as I saw fit rather than using the pre-set (although still customizable) annotations offered by FunctionPlot.

The one line of code that you show, together with the error message, makes it seem as if you're trying to modify SIRvector before it has even been defined. Surely that can't work.

If you need a more-thorough Answer, then you'll need to upload more-complete code.

First 146 147 148 149 150 151 152 Last Page 148 of 395