Carl Love

Carl Love

26109 Reputation

25 Badges

11 years, 59 days
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity

These are answers submitted by Carl Love

There are certain basic evaluations, mostly involving simple arithmetic, that are always done, even when you use the usual methods to delay evaluation. These are called "automatic simplifications," and you can read about them at ?ProgrammingGuide,Chapter03. There are two tricks that can be used to prevent or delay these automatic simplifications. They both involve encapsulating a number with backquotes (``), but they are very different.

The first method puts the numbers in the quotes. This is analogous to the convert(..., symbol) that Markiyan describes below (but is less to type). To force evaluation, i.e. to remove the effect of the quotes, one must apply parse to the quoted subparts. There are a number of subtleties to parse  that I won't go into here. This method is more of a "trick" that is used for display purposes, often in plots. I wouldn't call it an "official" method for preventing evaluation which one would use programmatically, but it can be used if you like the way it displays on screen.

The second and more robust method for preventing or delaying automatic simplification is to encapsulate the numbers as unevaluated function calls, using `` as the function. You force evaluation of this form simply by using expand.



ex:= (3*x^2-3*y^2)/(x-y);


ex1:= subs([x= `5`, y= `2`], ex);


evalindets(ex1, name, parse);


ex2:= subs([x= ``(5), y= ``(2)], ex);






Solving for a variable does not assign the value of that variable. You may assign it if you want, but that is often undesirable because it affects all expressions using that variable.. The usual method is to use the solution with the eval command to evaluate an expression at the solution. I hope this example will illustrate this concept for you:


f1:= randpoly(iDS, degree= 2);


f2:= randpoly(iDS, degree= 2);


M:= < < f2 > >; # a 1-element matrix.

M := Matrix(1, 1, {(1, 1) = -83*iDS^2-10*iDS+62})

sol:= solve(f1, {iDS});

{iDS = 73/194+(1/194)*6881^(1/2)}, {iDS = 73/194-(1/194)*6881^(1/2)}


{iDS = 73/194+(1/194)*6881^(1/2)}

eval(M[1,1], sol[1]);





 Don't hesistate to ask if you need more explanation.


Here are three ways based on the idea that what you want is the remainder from dividing by x[n]^6:

  1. algsubs(x[n]^6= 0, prd);
  2. simplify(prd, {x[n]^6 = 0});
  3. evala(Rem(prd, x[n]^6, x[n]));

And here are two ways based on simple truncation:

  1. convert(series(prd, x[n], 6), polynom);
  2. add(coeff(prd, x[n], k)*x[n]^k, k= 0..5);

All five methods give identical results.

You could rotate a semicircle of radius r around the x-axis:

f:= x-> sqrt(r^2-x^2):
int(Pi*f(x)^2, x= -r..r);
                            4     3
                            - Pi r

Regarding your question about the tickmarks: Each tick on the horizontal axis of the plot that you posted represents a separate power of 10, so it is appropriate that those ticks are linearly spaced. The ticks on the vertical axis of that plot that are logarithmically spaced. If you use a narrower range on the horizontal axis, you will get logarithmic ticks there also. You can achieve much finer control of the tickmarks by using some options to the plot command (see ?plot,tickmarks), but this can quickly get excessively complicated.

And to get the Moore-Penrose generalized inverse of a singular square matrix, use LinearAlgebra:-MatrixInverse with the method= pseudo option. For example,

A:= <<0,0>|<1,0>>;
                             [0  1]
                             [      ]
                             [0  0]
LinearAlgebra:-MatrixInverse(A, method= pseudo);
                             [0  0]
                             [      ]
                             [1  0]

If floating-point answers are acceptable, you can use the Statistics package:


or, the same thing with fancier syntax:

use Statistics in [Mean,Variance](A) end use;

Try convert(%, sin) or convert(%, cos). Does that give you what you want? If not, could you state more explicitly what is the pattern that you want?

Wolfram|Alpha is not exactly the same thing as Mathematica. The former is the online "knowledge base" that uses the latter as an engine. It's one thing to update a website, and another to distribute updates for a multitude of different users' systems. I'm glad that I don't have to install a Maple update every week.

The answers you got from fsolve are correct. The deviations accumulate because of round-off in the evaluation of xp, X, yp, and Y. That's just the nature of floating-point computations. The following example "tower" of computations at successively higher values of Digits shows that each answer returned by fsolve is correct to the requested number of digits, yet the "check" evaluation of the original equations is usually not accurate to that same number of digits.

p1,p2,p3,p4:= seq(randpoly([x,y]), k= 1..4):
for k from 3 to 15 by 2 do
   Digits:= k:
   soln:= fsolve({p1=p2, p3=p4}, {x,y});
   eval([p1,p2,p3,p4], soln)

Digits := 3
soln := {x = .448, y = -.492}
[-1.1, -1.1, -.99, -.999]
Digits := 5
soln := {x = .44765, y = -.49237}
[-1.138, -1.138, -1.0135, -1.0134]
Digits := 7
soln := {x = .4476498, y = -.4923714}
[-1.13839, -1.13838, -1.013304, -1.013301]
Digits := 9
soln := {x = .447649842, y = -.492371448}
[-1.1383856, -1.1383856, -1.01330066, -1.01330067]
Digits := 11
soln := {x = .44764984210, y = -.49237144750}
[-1.138385629, -1.138385629, -1.0133006602, -1.0133006606]
Digits := 13
soln := {x = .4476498420985, y = -.4923714475019}
[-1.13838562902, -1.13838562902, -1.013300660590, -1.013300660592]
Digits := 15
soln := {x = .447649842098485, y = -.492371447501895}
[-1.1383856290149, -1.1383856290149, -1.01330066059060, -1.01330066059061]

@amrramadaneg Enter the following command to Maple, and tell me what Maple says:


This is part of the answer of 13 Jan 2013 to which I was referring. I am not referring to your question about the 1200x800 system.


The following command should give you a number which is very close to proportional to the amount of memory used by the object stored in variable V, except for cases where V is a trivially small object.

length(sprintf("%m", eval(V)));

I haven't done tests to find the constant of proportionality. Hopefully someone else can do that, as I don't have time today. What the %m code to sprintf does is take the internal representation of the object in memory and converts it to a string of characters. It may restrict that to printable characters. So the constant of proportionality may be close to

256 / (number of printable characters in the character set),

where 256 is the number of possible byte values.

The constant may be different for different types of objects. Sorry, I haven't tested this. Hopefully someone else can take up that task.

I let expr represent your large expression. Then do

fd:= FileTools:-Text:-Open("C:/Users/Carl/desktop/archive.txt"):
seq(fprintf(fd, "%a\n\n", term), term in expr):

You need to use add instead of sum, because sum evaluates its arguments before adding them, and even before assigning values to the index variable. If you evaluate f(n), with n being just an unassigned variable, then you have an infinite recursion: the sequence f(n-2), f(n-4), ... never gets to a base value of f(0) or f(1) because every term has that unassigned n. You will get the same error if you simply try to evaluate f(a) by itself. Maple's three sequential operators---seq, add, and mul (but not $)---have special evaluation rules that allow for values to be assigned to the index variable before the expression using that index variable is evaluated. But the vast majority of other commands have their arguments evaluated before they are passed to the command.

Use add when the numeric limits of summation are known and you literally want to add the terms. Use sum for symbolic summation. If the items to be summed already exist in memory and can be accessed without a sequencing operation, then consider using prefix `+`. for example, if the items are already in a list L, then `+`(L[]) is often much faster than add(x, x= L). But, the `+` method also generates significantly more "garbage" (i.e. temporary memory usage).

Use display, or display3d--- it doesn't matter which. No capital D though. I needed to put a colon at the end of your first line and correct the spelling of "implicit" in your last line.

f:=(x,y,z)-> z=x^2+y^2;

If you're happy with the plot, save it to a variable:

p1:= %:


Again, save it to a variable:

p2:= %:


All that being said, an implicit plot is not a great choice for this problem, seeing as how your equations are already solved for z. You could just do this:

plot3d([x^2+y^2, 2-x^2-y^2], x= -5..5, y= -5..5);


First 370 371 372 373 374 375 376 Page 372 of 379