Venkat Subramanian

431 Reputation

13 Badges

15 years, 265 days

MaplePrimes Activity


These are replies submitted by

@acer 

Calling fsolve for procedural form of Maple's dsolve numeric with compile won't work. Hence, the request.

@acer 

 

It does run faster than uncompiled Newton calling compiled F, Jac and s3. In particular for larger valeus of N. Thanks for your attention.

 

f:=array([seq(evalf(-2*x[i]+x[i]^2+0.99/i^2)+alpha[1],i=1..N)]);

You can take this as f and create alpha as a parameter (in this case alpha[1]=0.01 gives a good solution).

Why are you writing a for loop? I am assuming that defining J as -diff(f,x) and calling the same will not work for compile?

 

I think for Maple's dsolve numeric you will need a single procedure without a global call to another procedure. I have to test and I will get back to you if your approach works. Typically we have to give a procedure for f, the slopes. Uncompiled dsolve numeric will work with global calls, not sure of compiled dsolve numeric.

thanks

 

@acer 

Acer, yes. I think one can have a parameter vector or list, number of equations, equation list, initial guess that can be expected from an user as an user input.

I realize that J3 is also a global procedure to be called. Didn't make a difference in this case. One can check the speed of the above code compared to fsolve and it is much faster already.

 

 

 

@tomleslie 

 

When you try Compiler:-Compile(p2) it says p1 not recongized in 

 

Warning, the function names {p1} are not recognized in the target language

 

I think one cannot return arrays when you are trying to compile, so p2 might have to be called as p2(y,F)

 

I am trying to write a Newton Raphson in Maple for multiple nonlinear equations. I can do that with sparse methods (better than fsolve). But compiled version would be great. 

for a given set of equations

eq:=[list of nonlinear equations in y[1], y[2], etc..]

 

I can  create a procedure for F (equations) and Jac(jacobian). but I want these written down in a single procedure to be able to compile.

 

@tomleslie 

Is it possible to get only contents of one procedure printed or added to an another procedure

 

for example

p1:=proc(y,F)

F[1]:=y[1];
F[2]:=y[2]-y[1]^2;
return 
end;

p2:=proc(y,F)
local err, F
err:=5;
if y[1]<1 do  
"here I want only F[1]:=y[1]; F[2]:=y[2]-y[1]^2;"
end;
end proc;

In general F might change depending on user input and number of entries in p1 might change (10 or 20 or more). But I want to create p2 without typing the content of p1 manually in p2.

I am trying to write some iterative procedures which can be compiled in Maple if there is a single procedure, hence the request.

Thanks

 

@Carl Love 

 Thanks

I can create F and Jac separately and compile them separately. Not sure how to proceed further. It is almost like we want a single procedure.

procedure for F

procedure for Jac

(those two are easy)

 

For example we want

newt:=proc(x,f,jac)

while err < 1e-5

(here only the content of F should come with no return)

(here only content of Jac should come with no return)

(Here I can call linearsolver that can be compiled)

update x..

end

 

How to create procedures like this?

I can merge two procedures using joinprocs, but don't know how to create a procedure like this which will call the content of another procedures without returns

 

 

@Carl Love 

Carl, any idea how you can do this in compiled form from Maple? This will be faster (compiled form)

Thanks

 

If your variables are x(z) and y[i](z), then y[j](z) cannot occur on the right hand side of d2. You can solve 2 variables from 2 equations.

 

Always make sure equations work without a loop outside, before you write inside a loop. If you post a classic worksheet code, I can try to fix it.

 

@Thomas Richard 

 

Maple's DAE solvers are not true DAE solvers. They only solve DAEs by trying to convert DAEs to ODEs. Maplesim has direct DAE solvers. My DAE models fail in Maple, but work in Maplesim. I just ran the PDE code given by me in the link http://www.mapleprimes.com/posts/149877-ODEs-PDEs-And-Special-Functions

 

It works in Maplesim. It is kind of a shame that one has to create a custom component just to solve DAEs in Maplesim as Maple cannot solve. If any one can help access maplesim DAE solvers from Maple directly, please let me know.

 

@Carl Love 

 

My computers have 64GB RAM, but that doesn't help. The issue is if you have 200 lines of codes and if you want to copy paste from one code to another or copy multiple lines of codes or edit, my mouse won't even work for 5 minutes in mw version. In mws versions, it is a breeze. I can copy 100s of lines with no trouble. Initialy my students try out the mw format, but eventually move to mws as they can't do efficient code writing/editing.

The only advantage I have found using mw is this. When you run executable codes from *.mws, the codes run and output is stored in text files (lets say). In mw format when you run this, it will open a nice window (text file) and you can see the results. It makes it easy to debug linking/compiling or other commands. I basically use mw format to run exes.

Regarding plots, that is more on the asthetics, I will pass on that. For any publications or presentations, I export data to excel and plot there.

When Maple stops releasing *.mws, I will stop paying for newer versions.

 

 

 

 

 

 

@yellowcanary 

 

Stick to 1D input and preferably *.mws format. You will save a lot of time and RAM when you edit and run large codes. I can never work with mw format which is slow (Java based). Maplesoft unfortunatley moved to *.mw for a dumbed down version and for doing secondary school and high school math. (Also web friendly output, platform independence, etc).

If I can be proved wrong by someone who can post the same code in 2 different formats (*.mws and *.mw) and convince me that mw format is better, I am open to change my mind.

@ I think your model is linear, so you may be able to solve a larger system of equations.

As mentioned before, lsode, gear, etc comes with limited functionality. range, parametric, compile form or events are not possible with lsode.

 

 

Did you read all the help files in dsolve and all the posts about the same?. Recently Carl gave examples for parametric output.

If you can give an example of 4 ODEs in which you use only 2 and explain what you want then you might get better answer. No one has the time to re do codes. Post the code and then ask for help. Don't post 100000 ODEs, just post 4 ODE case.

Also, output = array (datapoints) uses less RAM, so you can get output at certain points in time, interpolant = false can save memory too.

I don't want to disappoint you, but Maple's dsolve is not capable of solving large systems of ODEs as it does not use sparse methods to store or solve.  This is relevant only if use implicit=true, otherwise, it is just marching in time, so there is no linearsolve other than just marching in time as done for most solvers in Maple's dsolve.  Also stiff or any methods using Jacobian will be slow in Maple as it uses and stores a full matrix for the Jacobian instead of sparse methods.

You may be better off going to FORTRAN or C for that.

 

The highest I have solved are probably in the range of 500 to 1000 ODEs.

Of course if you write your own algorithm you can solve 10000 or more ODEs. 

 

I think you like using the GAMMA function, I understand that. If you can avoid that type of special function, C or Fortran codes will help or you have to define your own subroutines to find that.

 

and stiff = true? that works for this prolbem and will give you a procedure output with options to use parameters. You can use initial x value as an unknown parameter

First 13 14 15 16 17 18 Page 15 of 18