Carl Love

## 27214 Reputation

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

## A few tips to start you off....

Here's a few tips to start you on the right track, although I don't know yet if your problem can be solved by Maple. It may be able to do part of it, or maybe all of it.

1. The imaginary unit in Maple is capital I.
2. Whenever you refer to functions such as pi, phi, and v, you need to include the arguments: pi(x), phi(x), v(x).
3. Maple makes no meaningful distinction between partial and full derivatives; although you may be able to get the prettyprinter to display them differently. Since all your derivatives are taken with respect to x, you'll be better off just thinking of them as full derivatives.
4. The solve command does not solve differential equations. The dsolve command is for that. For this problem, you may need to use the DEtools package.

If you replace all three occurences of sum with add, then your function will work. However, it can be improved in several ways, which I'll write about later. I just wanted to get you a minimally working version before I work further with it.

Edit: Here are some improvements:

f:= proc(h::And(even,nonnegint))
option remember;
local m;
end proc:

f(2):= 3:

g:= proc(n::nonnegint)
local a,m;
end proc:

## Bug and Workaround...

That's definitely a bug! You can see what's going on if you change cos(2*Pi*k*x) to cos(Pi*k*x). In the former case, it seems as if exp(-2*I*Pi*x) is being erroneously simplified to 1. Here's a workaround: Change cos(2*Pi*k*x) to cos(A*Pi*k*x), evaluate the symbolic sum, and then eval the resulting hypergeometric expression at A= 2.

I'll submit an official bug report.

## Automatic simplification and ``(...) or...

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.

 > restart;
 > 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);

 > expand(ex2);

## Need to eval the expression at the solut...

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.

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

 > sol[1];

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

 > evalf(%);

 >

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

## Five ways...

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.

## Rotate a semicircle...

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

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

## Logarithmic tickmarks...

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 for square singular matrices......

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]

## By using Statistics package...

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

Statistics:-Mean(A);
Statistics:-Variance(A);

or, the same thing with fancier syntax:

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

## convert(%, sin) or convert(%, cos)...

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?

## WolframAlpha is not the same thing as Ma...

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 errors accrue in eval after fsolve r...

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)
od;

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]

## kernelopts(datalimit)...

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

kernelopts(datalimit);

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.

## Make internal rep a string: sprintf("%m"...

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.

 First 380 381 382 383 384 385 386 Page 382 of 389
﻿