sand15

510 Reputation

10 Badges

4 years, 295 days

MaplePrimes Activity


These are questions asked by sand15

Hi guys,

I have written a program in Maple 2016 (Windows 7) made of two parts :

  1. An initialization step where a formal system of algebraic equations (some non linear) is built
    Let S(U, P) this system, where U denotes a set of unknowns and P a set of parameters (see step 2 below)
  2. An iterative step where this system is solved with respect to U for different values of parameters P
    This loop has to be executed N times for values P1, ..., Pn, ... of P

I observe that the size of the memory (bottom right of the Maple window) inflates as the value of n increases.

I was able to isolate in the loop corresponding to step 2, the procedure MyProc I wrote which is responsible of this memory inflation.
Now I would like to manage this inflation (typically the memory size grows up to 3 GiB for n about one thousand) because of its very negative effects on the computational time (probably Maple does spend a lot of time in swapping operations).


Suspecting the remember process to be the source of this problem, I tried simple tricks such as

  • systematically write   > quantity := 'quantity';   for fome intermediate quantities
  • use forget  : for example MyProc contains a call to fsolve and,  after "local" declarations, I inserted  the command  forget(fsolve)   
  • in the the loop over n,  I even inserted the command forget(Myproc).

None of these tricks was to some extent efficient to contain the memory inflation.


I suppose it is a very common situation that people who use to develop code are familiar with. So maybe some of you could provide my some advices or move me towards "strategies" or "methodologies" to prevent this situation ?
My purpose here is not to ask you to solve my problem, but rather to ask youy to give me hints to be able to manage such kind of situations by myself.


Maybe this question is unorthodox and doesn't have its place here ?
It that case please let me know.

Thanks In Advance


PS : it would be very difficult for me to provide you the code : if it is a necessary condition for you to help me, just forget it, I will understand

I have a simple minded question :
How can I give an answer a Vote Up or select it as the Best Answer to a question ?

Hi guys,

 

I would like to convert a piecewise defined function of two variables into an if structure
Example :

F := (x,y) -> piecewise(x < 0, piecewise(y < 0, 0, 1), piecewise(y < 0, 1, 0));

What I expect is something like (the indentation is just for fun)
if x < 0 then
   if y < 0 then 0 else 1 end if;
else 
   if y < 0 then 1 else 0 end if;
 end if


I tried the following :

convert(F(x,y), `if`)  # but it only converts the "outer x condition" and keeps the "inner y conditions" unchanged

And next this :

map(u -> convert(u, `if`), F(x,y)):   # fails to give m
# and
map(u -> convert(u(x,y), `if`), F(x,y)): 
# ...

without success.

Can anoybody help me please.
I am also interested in an explanation of the reasons why the previous command do not work.

Thanks all


----------------------------------------------------------------------------------------------------------------------
Introduction

I have a matrix (named DC on the piece of code below) all the elements of which are complex numbers a+b*I with a and b floating point numbers.
I want to obtain the real part of DC.

Obviously, if you do something like :
DC := Matrix(2,2, [1.0+1.0*I, 1.0-1.0*I, -1.0+1.0*I, -1.0-1.0*I];
Re~(DC);

the result corresponds to the desired matrix

----------------------------------------------------------------------------------------------------------------------
Context

In fact this matrix DC comes from some computations  described in the piece of code below

# Purpose :
# Given N points in a plane (here  in [0,1]X[0,1]), compute the matrix DX of distances between these points
#
# Example : if Pi and Pj are two such points, DX[i,j]=DX[j,i] denotes the Euclidian distance between Pi and Pj
#
# As I did not be able to find any single function in MAPLE that would construct DX , I proceed that way :
#   1/ let X the (N,2) matrix that contains the coordinates of the N points
#   2/ I represent these  N points as N complex numbers (vector C)
#   3/ I construct the (N,N) matrix MC = <C | C …..| C>
#   4/ I put MC = C – Transpose(C) :
#   5/ I take the norm DX of each elements of DC : DX := abs~(DC)
#       At this point, DX should contain the desired distances
#       But, due to floating point arithmetics, each element of DX writes a+0.*I where a is some floating point number)
#   6/ Last stage : execute Re~(DX)
#

with(Statistics):
with(LinearAlgebra):

N := 4:
X := Matrix(N,2, convert(Sample(Uniform(0,1), 2*N), list)):  #just an example

C   := X[..,1] +~ X[..,2] *~I;
MC := Multiply(C, Vector[row](N, 1));
DC := MC - Transpose(MC);
DX := abs~(DC);
Re~(DX)


----------------------------------------------------------------------------------------------------------------------
 My observations : 

1/ Maple 2015, Windows XP, 64 bytes
Re~(DX) returns DX and does not remove the imaginary (0.*I) part
But  Matrix(N, N, Re~(convert(DC, list))) does (which is a satisfactory, even if not clever, stopgap)

Why (it is just a question to help me to understand correctly how MAPLE proceeds) Re~(DC) does not (seem) to work here ?


2/ Maple 2015.2, Mac OS X El Capitan
DX := abs~(DC) gives me this strange result :
If (for instance) DC[i, j] = -1 – 2*I, DX[i, j] = +1 + 2*I
According to the compatibility problems between Maple 2015.1 and “El Capitan” (fixed from February), could it remain a few other problems ?

Last but not lesat : Did I do any syntax error ?


 I look forward to your responses

I saw yesterday evening (at home) a very elegant answer to my question "Intersection of real intervals" .
Unfortunately I can't retrieve it this morning (I'm in the office)

It was something like  coulitbe('_x' ...) ... but I don't remember it entirely
I think it came from Carl Love or maybe Mac Dude

 Could you please send me it again ?

 

Thanks

First 14 15 16 17 Page 16 of 17