John May

Dr. John May

2896 Reputation

18 Badges

17 years, 158 days
Maplesoft
Pasadena, California, United States

Social Networks and Content at Maplesoft.com

Maple Application Center
I have been a part of the Mathematical Software Group at Maplesoft since 2007. I have a Ph.D in Mathematics from North Carolina State University as well as Masters and Bachelors degrees from the University of Oregon. I have been working on research in computational mathematics since 1997. I currently work on symbolic solvers and visualization as well as other subsystems of Maple.

MaplePrimes Activity


These are replies submitted by John May

Warning, solving for expressions other than names or functions is not
recommended.

The reason why this is not recommended is that Solve will try to automatically replace the expression you are solving for with a new variable.  That can lead to some unexpected results.  You are much better off doing the substitution yourself first. and then solving.

Or, in this case, when you are just trying to manipulate an equation and not actually "solve", try using isolate instead:

a2 := op(eliminate({x=cos(v), y=sin(v)},{v})[2]);
isolate(a2, y^2);


John May
Mathematical Software
Maplesoft

Warning, solving for expressions other than names or functions is not
recommended.

The reason why this is not recommended is that Solve will try to automatically replace the expression you are solving for with a new variable.  That can lead to some unexpected results.  You are much better off doing the substitution yourself first. and then solving.

Or, in this case, when you are just trying to manipulate an equation and not actually "solve", try using isolate instead:

a2 := op(eliminate({x=cos(v), y=sin(v)},{v})[2]);
isolate(a2, y^2);


John May
Mathematical Software
Maplesoft

For what it's worth, this pretty much what Maple's solve command does under the hood to try to solve this problem (solve({diff(y,x)},{x})).  In this case, it generates some much larger RootOf expressions and then it gets bogged down for a long time while trying to make its answer explicit, but it does eventually produce an answer - it is just a lot larger than the one Robert gets.


John May
Mathematical Software
Maplesoft

For problem 11, "Calculation of 10,000,000 fibonacci numbers"

Original code:

with(combinat): with(LinearAlgebra):

frnd:=rand(100..1000):
A := [seq(frnd(),i=1..10000000)]:
time(evalf(Map(a->fibonacci(a), A)));

was reported as taking about 821.140 sec on their "Intel Quad Core Q6600 processor with 2.4 GHz and 2 GB RAM running under Windows Vista Home".

It took 1180 seconds on my 2.13GHz Core2 machine.

Since floating point version of the Fibonacci numbers are being asked for, it doesn't make sense to compute them exactly then convert to floats. It looks like all the other platforms are computing them numerically:

frnd:=rand(100..1000):
A := Vector([seq(frnd(),i=1..10000000)], datatype=float[8]):
f:=subs(is5=evalhf(1/sqrt(5)),phi =evalhf((1+sqrt(5))/2), a->((phi^a-(-phi)^(-a))*is5));
time(map[evalhf](f, A));

takes 18.38s on my machine.


John May
Mathematical Software
Maplesoft

My point, and Robert's as well in the post below, is that there are no solutions if a0, a1, a2, c1, and c2 are considered as symbols.  Solving the system taking all the symbols as unknowns helps explain why that is the case.


John May
Mathematical Software
Maplesoft

My point, and Robert's as well in the post below, is that there are no solutions if a0, a1, a2, c1, and c2 are considered as symbols.  Solving the system taking all the symbols as unknowns helps explain why that is the case.


John May
Mathematical Software
Maplesoft

You can always call solve(sys, {m,n,k});

However, I think that your system is overdeterminined - too many equations and not enough unknowns.

If you call solve(sys); you'll see that there are only solutions for certain values of the parameters: c1 can vary but c2 = 0, a1 = 0, a2 = 0, and  a0 = 1.


John May
Mathematical Software
Maplesoft

You can always call solve(sys, {m,n,k});

However, I think that your system is overdeterminined - too many equations and not enough unknowns.

If you call solve(sys); you'll see that there are only solutions for certain values of the parameters: c1 can vary but c2 = 0, a1 = 0, a2 = 0, and  a0 = 1.


John May
Mathematical Software
Maplesoft

What I wrote was incorrect.  The first entry is not a bound.  I confused myself by looking at an uncharacteristic example.

Robert is right, the first entry is 0 by default.


John May
Mathematical Software
Maplesoft

What I wrote was incorrect.  The first entry is not a bound.  I confused myself by looking at an uncharacteristic example.

Robert is right, the first entry is 0 by default.


John May
Mathematical Software
Maplesoft

I agree. Roots should either call fsolve on floating-point input, or at least use a numeric check instead of an exact check. 

This same issue came up last week in another context (which is why I knew exactly what was causing the problem) and I have made the current maintainer of the Student packages aware of it.


John May
Mathematical Software, Maplesoft

As Scott points out, Roots should be called with the numeric option if you have floating point input: Student:-Calculus1:-Roots(sin(3*alpha)-.34, alpha = 0 .. 12, 'numeric'); Without the numeric option, Roots is calling 'solve' (instead of fsolve) and this solves the input converted to rational numbers: convert(sin(3*alpha)-.34, 'rational'); However, after it has the solutions, it calls evalf on them and sends the numerical solutions back to Roots(). Roots then plugs each solution back into the original floating point expression and checks whether they are exactly equal to 0. With the way floating point works, you have to be pretty lucky for the numerical roots to actually give you 0.0 when you plug them back in. Try it: seq(eval(sin(3*alpha)-.34, alpha=sol), sol=Student:-Calculus1:-Roots(sin(3*alpha)-.34, alpha = 0 .. 12, 'numeric')); If you are interested in the exact solutions instead of the numerical ones, you should not put floats in your input: Student:-Calculus1:-Roots(sin(3*alpha)-34/100, alpha = 0 .. 12); --- John May Mathematical Software, Maplesoft
This option was added to solve in Maple 10; if you are using Maple 9.5 or earlier it will give you an "Invalid arguments to solve" error. -- John May Mathematical Software, Maplesoft
Instead of using _EnvAllSolutions, I prefer to pass the AllSolutions option to solve: solve(cos(x/2) = 1/2, x, AllSolutions); it does the same thing, but it is more localized. -- John May
Unfortunately, right now, to get all of the solutions you also need the AllSolutions option: solve({y=2*x-5,y=2*x^2+2*x-21},{x,y},Explicit,AllSolutions); {x = -2*2^(1/2), y = -4*2^(1/2)-5}, {x = 2*2^(1/2), y = 4*2^(1/2)-5}
First 16 17 18 19 Page 18 of 19