Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

One way to answer the question is to solve the linear system. Since the system is homogenous (right sides are all 0), this  can be done like this:

A:= <
   1,  1,  1;
   1, -2, -1;
   2,  1,  3;
  -1,  2,  1;
>:
nops(LinearAlgebra:-NullSpace(A));
                               0

The nops is to count the vectors in the basis of the null space, which is the same thing as the dimension of the solution space.

I don't understand Kitonum's Answer at all, except that I agree with his first sentence "The dimension of the solution of a system is equal to the number of arbitrary constants in its solution." In particular, I don't see what t and derivatives have to do with this problem.

The problem can be solved with just fundamental arithmetic commands. No "solve" type command is needed. And, egads, certainly no nested loop is needed either.

Sol:= b-> `if`(igcd(b,10000)=1, 2391/b mod 10000, FAIL):

Your example:

Sol(297);
      9503

You could easily use the above to generate a list of all solution pairs, but I don't see the point of doing that. A solution exists iff and 10000 are relatively prime, in which case the solution is unique (modulo 10000).

To answer your titular question, "Can isolve be used with irem?": The msolve command would almost always be a better choice than doing that. But for the case at hand, even using msolve is overkill, and inefficient.
 

I find the syntax of implicitdiff overwhelming, and I always need to try several things before I find what works.

I will introduce a new dependent variable, F, to represent the expression that you want to differentiate. I'll consider c and r also as dependent variables. I'll consider the independent variables to be betavarphi, and x, in that order. (I don't think that it actually matters whether we consider x to be a variable or a constant.) So, the input system and variable specifications are

restart:

Sys:= {
   F = 
      c*(r-1)*exp(x*beta)/((1+varphi*exp(x*beta))
      *(-varphi*exp(x*beta)*r+varphi*exp(x*beta)+1)),
   c = exp(exp(x*beta)*(r-1)/(1+varphi*exp(x*beta))),
   ln(r) = varphi*exp(x*beta)*(r-1)/(1+varphi*exp(x*beta))-1
};
Vars:= {F, c, r}(beta, varphi, x);

It's not clear whether you want the first derivatives with respect to beta and varphi or the mixed second derivative with respect to both, or all three of those. So, I'll do all three:

implicitdiff(Sys, Vars, {F}, beta);
implicitdiff(Sys, Vars, {F}, varphi);
implicitdiff(Sys, Vars, {F}, beta, varphi);

Since I hate redundant code, here's a way to combine those three commands (although I admit that this requires expert-level Maple knowledge):

(op@curry(implicitdiff, Sys, Vars, {F})@op)~([[beta], [varphi], [beta,varphi]]);

 

It's a great Question about a not-well-known feature of Maple. The syntax required to use a procedure's indices as if they were arguments is awkward, but still doable. The following will work if you're always going to call f with an index or indices:

f:= (x,y)-> a[op(procname)]*x + b[op(procname)]*y;

Note that there's no index on in the definition, so it's impossible to use indices as if they were named parameters, such as your i; you must use the keyword procname.

The proper call to f is just as you suggested, f[3](x,y). But if you now call f without indices, you'll get a nonsense response, although not an error message. So, here's a more-robust treatment, essentially making the index a type-checked parameter:

f:= proc(x,y)
local i;
   if procname::'indexed' then 
      i:= [op(procname)];
      if nops(i) <> 1 then error "Exactly 1 index required" fi;
      i:= i[];
      if not i::'nonnegint' then error "Index must be nonnegative integer" fi
   else
      error "An index is required"
   fi;
  
   a[i]*x + b[i]*y
end proc:

Of course, it's up to you to decide what types and numbers of indices are allowed. Maple imposes no restrictions on that.

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.

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