69 Reputation

5 Badges

15 years, 343 days

MaplePrimes Activity

These are answers submitted by jan

You can try the select, remove or selectremove commands. in the abouve example, you can do the following to separate the real and complex solutions. q := {dsolve(diff(y(x),x) = 1/2*(6*x^3+2*sin(8*x)^2)/(y(x)^2))}; Then to get the real solution: remove (has, q, I); or to get the complex solutions select (has, q, I); Similarly, you can use these commands to separate numerical solutions: For example: q := {-1, 2, 3, 4, -5}; To get all positive solutions (including 0): select (x->evalb (x>=0), q); To get both sets you can also use selectremove (x->evalb (x>=0), q); Jan Bakus Applications Engineer, Maplesoft
I don't know enough about the Maple architecture to comment on speed of execution. However, here are a few things to make Maple go faster: Use floating point where possible Maple by default tries to keep results in exact form. For example the following expression
sin (Pi/2)
would be kept in its exact form, which is really slow. To speed things up you can make Maple evaluate the expression into a floating point number by
sin (Pi/2)
evalf (sin (Pi/2))
This can result is small improvement without doing a lot of work. Use evalhf Evalhf is a procedure that can execute another procedure or a statement using hardware floating point arithmetic. See ?evalhf for more details. Here is an example from one of the samples in Maple 10.
WaveGen := proc(
local i::posint, j::posint, tot::float, t::float, deltaT::float;

for i from 1 to Npoints do
	t := evalf (i/SampleFreq);
	for j from 1 to nc do
		tot:= tot + evalf (amps[j]*(sin(2*Pi*freqs[j]*t)));
	end do;
	SigData[i] := tot;
end do;

end proc:
This procedure can be called using evalhf as
evalhf (WaveGen (5, amps, freqs, Npoints, Fs, var(SigData)));
Compile the procedure You can also use the compiler to compile the procedure. The above procedure would be compiled using:
c_WaveGen := Compiler:-Compile (WaveGen):
Then you can execute the c_WaveGen procedure, which calls the compiled code.
c_WaveGen (5, amps, freqs, Npoints, Fs, SigData));
Timing improvement To get the sense of the possible speedup, here are timing for the SignalGeneration example in Maple 10.
  • Maple proc - 121 seconds
  • Evalhf - 0.484 seconds
  • Compile - 0.093 seconds
To see the example, go to the Help Menu, then Take a tour. From the worksheet, you can click on the Wave Generation link to bring up the example. Hope this helps, Jan Bakus Applications Engineer, Maplesoft
1 2 Page 2 of 2