## Momentum with two variable force

Maple 18

This app shows the calculation of the final speed of a body after it made contact with a variable force; Taking as reference the initial velocity, mass and graph of the variation of F as a function of time. That is, given the variable forces represented by the lines in the time intervals, we will show the equation of momentum and momentum; With their respective values, followed by their response.

Momentum_with_two_variable_force.mw

Lenin Araujo C.

## TravelingSalesman - speed...

How is it possible that  GraphTheory:-TravelingSalesman
is much slower than a simple brute-force solution?

 > restart;
 > n:=10:
 > A:=Matrix(n, (i,j)->`if`(i=j,0,n*(n-i)^4+2*j+(n-i)^2+j^3)):A[1,2]:=100*n^3:A;
 (1)
 > with(GraphTheory):
 > G:=Graph(A);
 (2)
 > t:=time[real](): TravelingSalesman(G); 'time'=time[real]()-t;
 (3)
 > ############### brute-force #############
 > t:=time[real](): P:=Iterator:-Permute([seq(2..n)]): cmin:=infinity: ord:=<"none">: for  v in P do   f:=add(A[v[k],v[k+1]],k=1..n-2) + A[1,v[1]]+A[v[n-1],1];   if f
 (4)
 > # And for n=11 I had to interrupt TravelingSalesman; # brute-force still works for n=12.

## MaplePrimes slow today

by: MaplePrimes

What's up with Mapleprimes's timing today? Every time I click on a Post or Question, the main post loads at the normal speed (which is slow to start with), and then it takes a full minute for the Answers or Replies (or lack thereof) to load. This has been consistent for every Post or Question that I've read today. Is anyone else experiencing this?

## Why difference in speed?...

The first example is very slow compared to the second.  The difference is in the definition of f().

restart;
y := int(1/(-0.4016e-1*m^(2/3)-0.211e-3*m^(5/3)), m);
f:= unapply(abs(y), m):
n := 500: ## sample size
M := <seq(2*idx/n,idx=1..n)>; ## m
Y := f~(M)+~Statistics:-Sample(Normal(0,3), n)^+; ## signal + noise

restart;
y := int(1/(-0.4016e-1*m^(2/3)-0.211e-3*m^(5/3)), m);
f:= (x) -> abs(subs(m=x,y));
n := 500: ## sample size
M := <seq(2*idx/n,idx=1..n)>; ## m
Y := f~(M)+~Statistics:-Sample(Normal(0,3), n)^+; ## signal + noise

## How to optimize solving process?...

I am able to get unlimeted numbers of equations describing my system. These equations are generally relate quotients of multivariate polynomials. Each additional equation I get is generally less than twice the length of the last, and it is not always the case that an equation is independant of the previous equations. Although I can get unlimited numbers of equations describing the system, it is not overdetermined.

I am interested in solving these equations for their variables. There are about 30 cases I am working on, the smallest number of evariables is six, the largest would be twenty.

I want to be able to solve these equations in the minimal time possible. But I don't understand the function solve well enough to do so.

How do I choose the equations to minimise the time taken for the command solve to proccess them?
How does the command solve work?

particularly:

1. if I process the command solve([Eq1,Eq2,Eq3...Eqn],variables) would the command solve([Eq[1],Eq[2],Eq[3]...Eq[n],Eq[n+1]],variables) take longer if Eq[n+1] is not indipendant of the previous equations?
2. Is there a way of checking whether Eq[n+1] is independant of the previous vequations, fast enough for it to be useful to check the equations before they are processed?
3. Does the ordering of the equations affect the speed of solve?
4. Is there a way of pre processing the equations before they are put into solve that will save it time? (for example factorising them, simplifying them etc...)

## Testing the speed of a procedure...

hi, is there any maple command that will allow me to test the speed of a procedure? something like the ctime in c++ or time in java.thanks

## evaluating forever......

hello people

I have this computation which has to do with my undergraduate project and each time I compute some work (vary parameters), it seems to evaluate forever. although my computer isn't recent and has 2GB of RAM the computation didn't seem to me as much of a task for it. computation works fine with some parameters as 0 but the moment I change it to a natural number, it evaluates forever.

Is there anyway I could speed up computation in maple? or do I just need a faster computer? but I have a dead line for next week. can I upload my worksheet for someone here to help me execute?

## how to speed up this part of code...

There is million items in list,

what is the difference between seq and for loop ?

is seq faster than for loop?

it is very slow when running code below, how to speed up this part of code?

https://gist.github.com/LovelyYanki/c0b61fbb9d5954b34e03#file-gistfile1-txt

HSKeyIn := Table();
for ij from 1 to 1685159 do
s := solve([mm[ij][1,1]=1,mm[ij][1,2]=1,mm[ij][1,3]=1],[a,b,c]):
if nops(s) > 0 then
if (rhs(s[1][1]) = 1 or rhs(s[1][1]) = 0) and (rhs(s[1][2]) = 1 or rhs(s[1][2]) = 0) and (rhs(s[1][3]) = 1 or rhs(s[1][3]) = 0) then
#print(lhs(indices(T3, pairs)[ij])):
#print("***"):
h := HilbertSeries([mm[ij][1,1],mm[ij][1,2],mm[ij][1,3]], {a,b,c}, z):
#print(h):
if not assigned(HSkeyIn[h]) then
if mod(ij, 100) = 0 then
print(ij):
end if:
HSkeyIn[h] := [[mm[ij][1,1],mm[ij][1,2],mm[ij][1,3]]]:
else
if mod(ij, 100) = 0 then
print(ij):
end if:
HSkeyIn[h] := [op(HSkeyIn[h]), [mm[ij][1,1],mm[ij][1,2],mm[ij][1,3]]]:
end if:

end if:
end if:
od:

## patmatch perfomance...

Hej guys,

in some of my Maple worksheets I'm using Maples fit-function to obtain a rational function fit to some data, as I'm interested in the zeros of enumerator and denominator, I chose my fit function accordingly. Afterwards I need to extract the results (mainly the zeros) and do some more calculation steps with them. When evaluating rational functions of high degree, I noticed that my way of extracting the results (I'm using patmatch) becomes increasingly slow up to the point where it takes a couple of minutes to extract 10 numbers.
E.g. the following minimal example (download link at the bottom) takes more than 20 minutes on my machine (Maple 18.01 Build ID 935137; Red Hat Version 6.6 running on system with an i5-3570, 8 GB of RAM). Additionally, the calculation requires an unreasonable amount of RAM.
I can work around the problem to some degree by extracting the leading coefficient beforehand, resulting in a substantial speed up, still I think that there might be some error in the code or my usage of patmatch.

Is there another way to extract these numbers in a similarly simple fashion?

Cheers,

Sören

 >

a pathmatch with 9 variables requires roughly 200 MB of memory and takes about 7 s to finish on an i5-3570 CPU:

 >
 (1)
 >
 (2)
 >
 (3)

a pathmatch with 9 variables requires roughly 2.2 GB (!) of memory and takes about 20 min (!) to finish on an i5-3570 CPU:

 >
 (4)
 >
 (5)
 >
 (6)
 >

## A major-league pitcher ...

A major-league pitcher releases a ball at a point 6 feet above the ground and 58 feet from home plate at a speed of 100 mi/hr ,

If gravity had no effect, the ball would travel along a line and cross home plate 4 feet off the ground. Find the drop D caused by gravity.

NB: in this problem the angle alpha is the angle between the horizontal and the direction of the released ball. Since the ball is dropping, alpha will be negative.

## Using the position vector

Maple 18

This is an application of vector position to better understand the vector speed and acceleration is a well defined vector space. Fully developed with embedded components for proper use.

Vector_Posición.mw                   (in spanish)

L. Araujo C.

Physics Pure

Computer Science

## System of equations solve, solutions may be lost. ...

Hi MaplePrime-ers!

I've been using the Maple(17) toolbox in Matlab(2012b) to quickly enumerate systems of equations by: (i) solving them symbolically, (ii) using unapply to make them functions, (iii) then supplying the points (driver equations) to get the system solution.  Speed is a must, because there may be 3 million+ systems to solve.  Symbolics is also very important because I am evaluating topology, so the structure of the equations may change, and therefore a functional approach will not work.

I have had success (seen in the first code snippet).  I would like similiar behaviour in the second code snippet, but sometimes I get 'solutions may be lost' as an error message,  or 'Error, (in unapply) variables must be unique and of type name'

The system of equations include:  Linear equations, 5th order polynomials, absolute functions, and pieceiwse functions.

Here is code with a topology that solves:

#Interconnection Equations
eq2[1] := FD_T + EM2_T = 0;
eq2[2] := ICE_T + GEN_T = 0;
eq2[3] := EM2_A + GEN_A + BAT_A = 0;
eq2[4] := -FD_W + EM2_W = 0;
eq2[5] := -ICE_W + GEN_W = 0;
eq2[6] := -EM2_V + GEN_V = 0;
eq2[7] := -EM2_V + BAT_V = 0;

#ICE
eq_c[1] := ICE_mdot_g=((671.5) + (-21.94)*ICE_T + (0.1942)*ICE_W + (0.5113)*ICE_T^2 + (-0.01271)*ICE_T*ICE_W + ( -0.0008761)*ICE_W^2 + (-0.006071)*ICE_T^3 + (9.867e-07)*ICE_T^2*ICE_W + (5.616e-05)*ICE_T*ICE_W^2 + (1.588e-06)*ICE_W^3 + (3.61e-05)*ICE_T^4 + (8.98e-07)*ICE_T^3*ICE_W + (-2.814e-07)*ICE_T^2*ICE_W^2 + (-8.121e-08)*ICE_T*ICE_W^3 + ( -8.494e-08 )*ICE_T^5 + (-2.444e-09)*ICE_T^4*ICE_W + (-9.311e-10)*ICE_T^3*ICE_W^2 + ( 5.835e-10)*ICE_T^2*ICE_W^3 ) *1/3600/1000 * ICE_T * ICE_W;

#BAT
eq_c[2] := BAT = 271;

#EM2
EM2_ReqPow_eq := (-148.3) + (4.267)*abs(EM2_W) + (12.77)*abs(EM2_T) + (-0.0364)*abs(EM2_W)^2 + ( 1.16)*abs(EM2_W)*abs(EM2_T) + (-0.258)*abs(EM2_T)^2 + ( 0.0001181)*abs(EM2_W)^3 + (-0.0005994)*abs(EM2_W)^2*abs(EM2_T) + ( 0.0001171)*abs(EM2_W)*abs(EM2_T)^2 + (0.001739 )*abs(EM2_T)^3 + (-1.245e-07 )*abs(EM2_W)^4 + ( 1.2e-06)*abs(EM2_W)^3*abs(EM2_T) + ( -1.584e-06)*abs(EM2_W)^2*abs(EM2_T)^2 + ( 4.383e-07)*abs(EM2_W)*abs(EM2_T)^3 + (-2.947e-06)*abs(EM2_T)^4;
eq_c[3] := EM2_P = piecewise( EM2_T = 0, 0, EM2_W = 0, 0, EM2_W*EM2_T < 0,-1 * EM2_ReqPow_eq, EM2_ReqPow_eq);
eq_c[4] := EM2_A = EM2_P/EM2_V;

#GEN
GEN_ReqPow_eq:= (-5.28e-12) + ( 3.849e-14)*abs(GEN_W) + (-71.9)*abs(GEN_T) + (-1.168e-16)*abs(GEN_W)^2 +(1.296)*abs(GEN_W)*abs(GEN_T) + (2.489)*abs(GEN_T)^2 + (1.451e-19)*abs(GEN_W)^3 + (0.0001326)*abs(GEN_W)^2*abs(GEN_T) + (-0.008141)*abs(GEN_W)*abs(GEN_T)^2 + (-0.004539)*abs(GEN_T)^3 +(-6.325e-23)*abs(GEN_W)^4 + (-2.091e-07)*abs(GEN_W)^3*abs(GEN_T) + ( 3.455e-06)*abs(GEN_W)^2*abs(GEN_T)^2 + ( 2.499e-05)*abs(GEN_W)*abs(GEN_T)^3 + (-5.321e-05)*abs(GEN_T)^4;
eq_c[5] := GEN_P = piecewise( GEN_T = 0, 0, GEN_W = 0, 0, GEN_W*GEN_T < 0,-1 * GEN_ReqPow_eq, GEN_ReqPow_eq);
eq_c[6] := GEN_A = GEN_P/GEN_V;

#ASSUMPTIONS
assume(BAT_V::nonnegative);
assume(FD_W::nonnegative);

#FINAL EQUATIONS

sys_eqs2 := convert(eq2,set) union {eq_c[1],eq_c[2],eq_c[3],eq_c[4],eq_c[5],eq_c[6]};

#Selecting which variables to solve for:

drivers2:= { ICE_T,ICE_W,FD_T,FD_W};
symvarnames2:=select(type,indets(convert(sys_eqs2,list)),name);
notdrivers2:=symvarnames2 minus drivers2;

#Symbolic solve

sol2:=solve(sys_eqs2,notdrivers2) assuming real:
symb_sol2:=unapply(sol2,convert(drivers2,list)):

#Enumerate (there will generally be about 40, not 6)

count := 0;
for i1 from 1 to 40 do
for i2 from 1 to 40 do
for i3 from 1 to 40 do
for i4 from 1 to 40 do
count := count + 1;
solsol2(count) := symb_sol2(i1,i2,i3,i4);
od;
od;
od;
od;
count;

This works great!  I would like simliar output in my second code snippet, but this time with more inputs to symb_sol.  However, if I try and change the interconnection equations a little, and add a piecewise function, and another driver... (differences in bold)

#Interconnection Equations
eq1[1] := FD_T+EM2_T = 0;
eq1[2] := ICE_T+GBb_T = 0;
eq1[3] := GEN_T+GBa_T = 0;
eq1[4] := EM2_A+GEN_A+BAT_A = 0;
eq1[5] := -FD_W+EM2_W = 0;
eq1[6] := -GEN_W+GBa_W = 0;
eq1[7] := -ICE_W+GBb_W = 0;
eq1[8] := -EM2_V+GEN_V = 0;
eq1[9] := -EM2_V+BAT_V = 0;

#ICE
eq_c[1] := ICE_mdot_g=((671.5) + (-21.94)*ICE_T + (0.1942)*ICE_W + (0.5113)*ICE_T^2 + (-0.01271)*ICE_T*ICE_W + ( -0.0008761)*ICE_W^2 + (-0.006071)*ICE_T^3 + (9.867e-07)*ICE_T^2*ICE_W + (5.616e-05)*ICE_T*ICE_W^2 + (1.588e-06)*ICE_W^3 + (3.61e-05)*ICE_T^4 + (8.98e-07)*ICE_T^3*ICE_W + (-2.814e-07)*ICE_T^2*ICE_W^2 + (-8.121e-08)*ICE_T*ICE_W^3 + ( -8.494e-08 )*ICE_T^5 + (-2.444e-09)*ICE_T^4*ICE_W + (-9.311e-10)*ICE_T^3*ICE_W^2 + ( 5.835e-10)*ICE_T^2*ICE_W^3 ) *1/3600/1000 * ICE_T * ICE_W;

#BAT
eq_c[2] := BAT = 271;

#EM2
EM2_ReqPow_eq := (-148.3) + (4.267)*abs(EM2_W) + (12.77)*abs(EM2_T) + (-0.0364)*abs(EM2_W)^2 + ( 1.16)*abs(EM2_W)*abs(EM2_T) + (-0.258)*abs(EM2_T)^2 + ( 0.0001181)*abs(EM2_W)^3 + (-0.0005994)*abs(EM2_W)^2*abs(EM2_T) + ( 0.0001171)*abs(EM2_W)*abs(EM2_T)^2 + (0.001739 )*abs(EM2_T)^3 + (-1.245e-07 )*abs(EM2_W)^4 + ( 1.2e-06)*abs(EM2_W)^3*abs(EM2_T) + ( -1.584e-06)*abs(EM2_W)^2*abs(EM2_T)^2 + ( 4.383e-07)*abs(EM2_W)*abs(EM2_T)^3 + (-2.947e-06)*abs(EM2_T)^4;
eq_c[3] := EM2_P = piecewise( EM2_T = 0, 0, EM2_W = 0, 0, EM2_W*EM2_T < 0,-1 * EM2_ReqPow_eq, EM2_ReqPow_eq);
eq_c[4] := EM2_A = EM2_P/EM2_V;

#GEN
GEN_ReqPow_eq:= (-5.28e-12) + ( 3.849e-14)*abs(GEN_W) + (-71.9)*abs(GEN_T) + (-1.168e-16)*abs(GEN_W)^2 +(1.296)*abs(GEN_W)*abs(GEN_T) + (2.489)*abs(GEN_T)^2 + (1.451e-19)*abs(GEN_W)^3 + (0.0001326)*abs(GEN_W)^2*abs(GEN_T) + (-0.008141)*abs(GEN_W)*abs(GEN_T)^2 + (-0.004539)*abs(GEN_T)^3 +(-6.325e-23)*abs(GEN_W)^4 + (-2.091e-07)*abs(GEN_W)^3*abs(GEN_T) + ( 3.455e-06)*abs(GEN_W)^2*abs(GEN_T)^2 + ( 2.499e-05)*abs(GEN_W)*abs(GEN_T)^3 + (-5.321e-05)*abs(GEN_T)^4;
eq_c[5] := GEN_P = piecewise( GEN_T = 0, 0, GEN_W = 0, 0, GEN_W*GEN_T < 0,-1 * GEN_ReqPow_eq, GEN_ReqPow_eq);
eq_c[6] := GEN_A = GEN_P/GEN_V;

#GB
FiveSpeedGearbox_R := proc(ig)
local i ,eq;
i[1]:=3.32;
i[2]:=2;
i[3]:=1.36;
i[4]:=1.01;
i[5]:=0.82;
eq:= piecewise(ig=1,i[1],ig=2, i[2],ig=3,i[3],ig=4,i[4],ig=5,i[5],1);
return eq(ig);
end proc;

eq_c[7] := GBb_T = -1/GB_R * GBa_T;
eq_c[8] := GBb_W = GB_R * GBa_W;
eq_c[9] := GB_R = FiveSpeedGearbox_R(ig);

#System Equations
sys_eqs := convert(eq1,set) union convert(eq_c,set);

#Solve for variables
symvarnames:=select(type,indets(convert(sys_eqs,list)),name);
drivers:= {ig, ICE_T,ICE_W,FD_T,FD_W};
not_drivers := symvarnames minus drivers;

#Assumptinons

assume(BAT_V::nonnegative);
assume(FD_W::nonnegative);

sol:=(solve(sys_eqs,not_drivers) assuming real);

symb_sol:=unapply(sol,convert(drivers,list)): ---> Error, (in unapply) variables must be unique and of type name

Subsequent parts don't work...

count := 0;
for i1 from 1 to 40 do
for i2 from 1 to 40 do
for i3 from 1 to 40 do
for i4 from 1 to 40 do
for i5 from 1 to 40 do
count := count + 1;
solsol2(count) := symb_sol2(i1,i2,i3,i4,5);
od;
od;
od;
od;
od;
count;

While running the last line sol:, 1 of 2 things will happen, depending on the solver. Maple17 will take a long time (30+ minutes) to solve, then report nothing, or sol will solve, but will report "some solutions have been lost".

Afterwards, evaluating symb_sol(0,0,0,0,0) will return a viable solution (real values for each of the variables).  Whereas evaluating symb_sol(0,X,0,0,0), where X <> 0, will return and empty list [].

Does anyone know how to (i) speed up the symbolic solve time?  (ii) Return ALL of the solutions?

Thanks in advance for reading this.  I've really no idea why this isn't working.  I've also attached two worksheets with the code: noGB.mw   withGB.mw

## Perl vs. Maple. (Multiplicative Partition Function...

Greetings to all.

The multiplicative partition function is defined here at Wikipedia and was recently the subject of a discussion at Math Stackexchange.

I posted two solutions to the task of computing this function at the above page that use Maple code. One of them employs the Polya Enumeration Theorem and is of mostly theoretical interest as it cannot be used to effectively compute the function for n with many factors. I posted two additional implementations in order to remedy this defect, one of them in Maple and the other in Perl. I think the Maple implementation is easy enough to read not to require additional commentary. Note, however, that even though the Maple code and the Perl code implement the same algorithm (dynamic programming), the Maple version is dramatically slower than the Perl version and consumes a lot of memory. E.g. Maple takes 58 seconds for the value for 9! and Perl takes 1.5 seconds.

My question is, can someone explain this difference? Note that both are interpreted languages so there is no gain due to potential compilations.

This is with Maple 15 (X86 64 LINUX).

Best regards,

Marko Riedel

## Solve: High dimensional non-linear system, faster ...

Hi,

I have been solving a system of non-linear ODE's for their steady states. This involves solving the rhs of the ODE's =0.

Hence I have been using "solve" in maple to solve a non-linear system.

Recently I have added more detail to the problem and now I am solving eight equations for eight variables and i've left overnight and maple still didnt find a solution. When sigma1=sigma2=0 below the problem is effectively 5-d and maple breezes through the calculation.