MaplePrimes Posts

MaplePrimes Posts are for sharing your experiences, techniques and opinions about Maple, MapleSim and related products, as well as general interests in math and computing.

Latest Post
  • Latest Posts Feed

  • One of the interesting things about the Physics package is that it was designed from scratch to extend the domain of operations of the Maple system from commutative variables to one that includes commutative, anticommutative and nonocommutative variables, as well as abstract vectors and related (nabla) differential operators. In this line we have, among others, the following Physics commands working with this extended domain: `*` , `.` , `^` , diff , Expand , Normal , Simplify , Gtaylor , and Coefficients .

     

    More recently, Pascal Szriftgiser (from Laboratoire PhLAM, Université Lille 1, France), suggested a similar approach to factorize expressions involving noncommutative variables. This is a pretty complicated problem though. Pascal's suggestion, however, spinned around an idea beautiful for its simplicity, similar to what is done in the experimental Physics command, PerformOnAnticommutativeSystem , that is, to transform the problem into one that can be treated with the command that works only with commutative variables and from there extract the result for noncommutative ones.The approach has limitations but it is surprising how far one can go using imaginative algebraic manipulations to extend these commands that otherwise only work with commutative variables.

     

    In brief, we now have a new command, Physics:-Factor, with already powerful performance for factorizing algebraic expressions that involve commutative, noncommutative and anticommutative variables, making Maple's mathematical capabilities more advanced in very interesting directions. This command is in fact useful not just in advanced theoretical physics, but for instance also when working with noncommutative symbols representing abstract matrices (that can have dependency, and so they can be differentiated before saying anything about their components, multiplied, and be present int  expressions that in turn can be expanded, simplified and now also factorized), and also useful with expressions that include differential operators, now that within Physics you can compute with the the covariant and noncovariant derivatives D_  and d_ algebraically. For instance, how about solving differential equations using Physics:-Factor (reducing their order by means of factoring the involved differential operators) ? :)

     

    What follows are some basic algebraic examples illustrating the novelty, and as usual to reproduce the results in this worksheet you need to update your Physics library with the one available in the Maplesoft R&D Physics webpage.

     

    Physics:-Version()[2]

    `2015, September 25, 7:48 hours`

    (1)

    with(Physics); -1; Setup(quantumoperators = {a, b, c, d, e}, mathematicalnotation = true)

    [mathematicalnotation = true, quantumoperators = {a, b, c, d, e}]

    (2)

    First example, because of using mathematical notation, noncommutative variables are displayed in different color (olive)

    Physics:-`*`(Physics:-`^`(alpha, 2), Physics:-`^`(a, 2))+Physics:-`*`(Physics:-`*`(Physics:-`*`(alpha, sqrt(2)), a), b)+Physics:-`*`(Physics:-`*`(Physics:-`*`(Physics:-`*`(4, sqrt(2)), lambda), Physics:-`^`(b, 2)), c)+Physics:-`*`(Physics:-`*`(Physics:-`*`(Physics:-`*`(Physics:-`*`(4, lambda), alpha), b), c), a)+Physics:-`*`(Physics:-`*`(Physics:-`*`(Physics:-`*`(Physics:-`*`(4, lambda), sqrt(2)), b), c), b)+Physics:-`*`(Physics:-`*`(16, Physics:-`^`(lambda, 2)), Physics:-`^`(Physics:-`*`(b, c), 2))+Physics:-`*`(Physics:-`*`(Physics:-`*`(Physics:-`*`(Physics:-`*`(4, alpha), lambda), a), b), c)+Physics:-`*`(Physics:-`*`(Physics:-`*`(sqrt(2), alpha), b), a)+Physics:-`*`(2, Physics:-`^`(b, 2))

    alpha^2*Physics:-`^`(a, 2)+alpha*2^(1/2)*Physics:-`*`(a, b)+4*2^(1/2)*lambda*Physics:-`*`(Physics:-`^`(b, 2), c)+4*lambda*alpha*Physics:-`*`(b, c, a)+4*2^(1/2)*lambda*Physics:-`*`(b, c, b)+16*lambda^2*Physics:-`^`(Physics:-`*`(b, c), 2)+4*lambda*alpha*Physics:-`*`(a, b, c)+alpha*2^(1/2)*Physics:-`*`(b, a)+2*Physics:-`^`(b, 2)

    (3)

    Physics:-Factor(alpha^2*Physics:-`^`(a, 2)+alpha*2^(1/2)*Physics:-`*`(a, b)+4*2^(1/2)*lambda*Physics:-`*`(Physics:-`^`(b, 2), c)+4*lambda*alpha*Physics:-`*`(b, c, a)+4*2^(1/2)*lambda*Physics:-`*`(b, c, b)+16*lambda^2*Physics:-`^`(Physics:-`*`(b, c), 2)+4*lambda*alpha*Physics:-`*`(a, b, c)+alpha*2^(1/2)*Physics:-`*`(b, a)+2*Physics:-`^`(b, 2))

    Physics:-`^`(4*lambda*Physics:-`*`(b, c)+a*alpha+2^(1/2)*b, 2)

    (4)

    A more involved example from a physics problem, illustrating that the factorization is also happening within function's arguments, as well as that we can also correctly expand mathematical expressions involving noncommutative variables

    PDEtools:-declare((a, b, c, g)(x, y)):

    a(x, y)*`will now be displayed as`*a

     

    b(x, y)*`will now be displayed as`*b

     

    c(x, y)*`will now be displayed as`*c

     

    g(x, y)*`will now be displayed as`*g

    (5)

    Physics:-Intc(Physics:-`^`(Physics:-`*`(Physics:-`*`(Physics:-`*`(4, Physics:-Dagger(b(x, y))), c(x, y)), lambda)+Physics:-`*`(Physics:-`*`(Physics:-`*`(alpha, f(t)), a(x, y)), Physics:-Dagger(a(x, y)))+Physics:-`*`(Physics:-`*`(sqrt(2), g(x, y)), b(x, y)), 2), x, y)

    Int(Int(Physics:-`^`(4*lambda*Physics:-`*`(Physics:-Dagger(b(x, y)), c(x, y))+alpha*f(t)*Physics:-`*`(a(x, y), Physics:-Dagger(a(x, y)))+2^(1/2)*g(x, y)*b(x, y), 2), x = -infinity .. infinity), y = -infinity .. infinity)

    (6)

    So first expand ...

    expand(Int(Int(Physics:-`^`(4*lambda*Physics:-`*`(Physics:-Dagger(b(x, y)), c(x, y))+alpha*f(t)*Physics:-`*`(a(x, y), Physics:-Dagger(a(x, y)))+2^(1/2)*g(x, y)*b(x, y), 2), x = -infinity .. infinity), y = -infinity .. infinity))

    Int(Int(16*lambda^2*Physics:-`*`(Physics:-Dagger(b(x, y)), c(x, y), Physics:-Dagger(b(x, y)), c(x, y))+4*lambda*alpha*f(t)*Physics:-`*`(Physics:-Dagger(b(x, y)), c(x, y), a(x, y), Physics:-Dagger(a(x, y)))+4*lambda*2^(1/2)*g(x, y)*Physics:-`*`(Physics:-Dagger(b(x, y)), c(x, y), b(x, y))+4*alpha*f(t)*lambda*Physics:-`*`(a(x, y), Physics:-Dagger(a(x, y)), Physics:-Dagger(b(x, y)), c(x, y))+alpha^2*f(t)^2*Physics:-`*`(a(x, y), Physics:-Dagger(a(x, y)), a(x, y), Physics:-Dagger(a(x, y)))+alpha*f(t)*2^(1/2)*g(x, y)*Physics:-`*`(a(x, y), Physics:-Dagger(a(x, y)), b(x, y))+4*2^(1/2)*g(x, y)*lambda*Physics:-`*`(b(x, y), Physics:-Dagger(b(x, y)), c(x, y))+2^(1/2)*g(x, y)*alpha*f(t)*Physics:-`*`(b(x, y), a(x, y), Physics:-Dagger(a(x, y)))+2*g(x, y)^2*Physics:-`^`(b(x, y), 2), x = -infinity .. infinity), y = -infinity .. infinity)

    (7)

    Now retrieve the original expression by recursing over the arguments and so factoring the integrand

    Physics:-Factor(Int(Int(16*lambda^2*Physics:-`*`(Physics:-Dagger(b(x, y)), c(x, y), Physics:-Dagger(b(x, y)), c(x, y))+4*lambda*alpha*f(t)*Physics:-`*`(Physics:-Dagger(b(x, y)), c(x, y), a(x, y), Physics:-Dagger(a(x, y)))+4*lambda*2^(1/2)*g(x, y)*Physics:-`*`(Physics:-Dagger(b(x, y)), c(x, y), b(x, y))+4*alpha*f(t)*lambda*Physics:-`*`(a(x, y), Physics:-Dagger(a(x, y)), Physics:-Dagger(b(x, y)), c(x, y))+alpha^2*f(t)^2*Physics:-`*`(a(x, y), Physics:-Dagger(a(x, y)), a(x, y), Physics:-Dagger(a(x, y)))+alpha*f(t)*2^(1/2)*g(x, y)*Physics:-`*`(a(x, y), Physics:-Dagger(a(x, y)), b(x, y))+4*2^(1/2)*g(x, y)*lambda*Physics:-`*`(b(x, y), Physics:-Dagger(b(x, y)), c(x, y))+2^(1/2)*g(x, y)*alpha*f(t)*Physics:-`*`(b(x, y), a(x, y), Physics:-Dagger(a(x, y)))+2*g(x, y)^2*Physics:-`^`(b(x, y), 2), x = -infinity .. infinity), y = -infinity .. infinity))

    Int(Int(Physics:-`^`(4*lambda*Physics:-`*`(Physics:-Dagger(b(x, y)), c(x, y))+alpha*f(t)*Physics:-`*`(a(x, y), Physics:-Dagger(a(x, y)))+2^(1/2)*g(x, y)*b(x, y), 2), x = -infinity .. infinity), y = -infinity .. infinity)

    (8)

    This following one looks simpler but it is actually more complicated:

    Physics:-`*`(Physics:-Commutator(a, b), c)

    Physics:-`*`(Physics:-Commutator(a, b), c)

    (9)

    expand(Physics:-`*`(Physics:-Commutator(a, b), c))

    Physics:-`*`(a, b, c)-Physics:-`*`(b, a, c)

    (10)

    The complication consists of the fact that the standard factor  command, that assumes products are commutative, can never deal with factors like Physics:-Commutator(a, b) = a*b-a*b because if products were commutative these factors are equal to 0. Of course we not just us factor but include a number of algebraic manipulations before using it, so that the approach handles these cases nicely anyway

    Physics:-Factor(Physics:-`*`(a, b, c)-Physics:-`*`(b, a, c))

    Physics:-`*`(Physics:-`*`(a, b)-Physics:-`*`(b, a), c)

    (11)

    This other one is more complicated:

    Physics:-`*`(Physics:-`*`(a, b)-Physics:-`*`(b, a), a+Physics:-`*`(beta, b)+Physics:-`^`(c, 2))

    Physics:-`*`(Physics:-`*`(a, b)-Physics:-`*`(b, a), a+beta*b+Physics:-`^`(c, 2))

    (12)

    When you expand,

    expand(Physics:-`*`(Physics:-`*`(a, b)-Physics:-`*`(b, a), a+beta*b+Physics:-`^`(c, 2)))

    Physics:-`*`(a, b, a)+beta*Physics:-`*`(a, Physics:-`^`(b, 2))+Physics:-`*`(a, b, Physics:-`^`(c, 2))-Physics:-`*`(b, Physics:-`^`(a, 2))-beta*Physics:-`*`(b, a, b)-Physics:-`*`(b, a, Physics:-`^`(c, 2))

    (13)

    you see that there are various terms involving the same noncommutative operands, just multiplied in different order. Generally speaking the limitation (n this moment) of the approach is: "there cannot be more than 2 terms in the expanded form containing the same operands" . For instance in (13) the 1st and 4th terms have the same operands, that are actually also present in the 5th term but there you also have beta and for that reason (involving some additional manipulations) it can be handled:

    Physics:-Factor(Physics:-`*`(a, b, a)+beta*Physics:-`*`(a, Physics:-`^`(b, 2))+Physics:-`*`(a, b, Physics:-`^`(c, 2))-Physics:-`*`(b, Physics:-`^`(a, 2))-beta*Physics:-`*`(b, a, b)-Physics:-`*`(b, a, Physics:-`^`(c, 2)))

    Physics:-`*`(Physics:-`*`(a, b)-Physics:-`*`(b, a), a+beta*b+Physics:-`^`(c, 2))

    (14)

    Recalling, in all these examples, the task is actually accomplished by the standard factor  command, and the manipulations consist of ingeniously rewriting the given problem as one that involves only commutative variables, and from extract the correct result for non commutative variables.

     

    To conclude, here is an example where the approach implemented does not work (yet) because of the limitation mentioned in the previous paragraph:

    Physics:-`^`(Physics:-Commutator(a, b)+c, 2)

    Physics:-`^`(Physics:-Commutator(a, b)+c, 2)

    (15)

    expand(Physics:-`^`(Physics:-Commutator(a, b)+c, 2))

    Physics:-`*`(a, b, a, b)-Physics:-`*`(a, Physics:-`^`(b, 2), a)+Physics:-`*`(a, b, c)-Physics:-`*`(b, Physics:-`^`(a, 2), b)+Physics:-`*`(b, a, b, a)-Physics:-`*`(b, a, c)+Physics:-`*`(c, a, b)-Physics:-`*`(c, b, a)+Physics:-`^`(c, 2)

    (16)

    In this expression, the 1st, 2nd, 4th and 5th terms have the same operands a, b, a, b and then there are four terms containing the operands a, b, c. We do have an idea of how this could be done too ... :) To be there in one of the next Physics updates.

    NULL

    NULL


    Download Physics[Factor].mw

    Edgardo S. Cheb-Terrab
    Physics, Differential Equations and Mathematical Functions, Maplesoft

    We have a new video about plotting with procedures, specifically on how to avoid an error related to evaluation that many people make. 

    The worksheet I used in the video is available here:  PlottingWithProcedures.mw

    By the way, this mistake doesn't occur just in the context of plotting. Users of Optimization commands (and other commands that allow functions to be expressed as either an expression in a variable or as a procedure) frequently run into this problem too.

     

    We are happy to announce that Maple T.A. now supports the Learning Tools Interoperability® (LTI) standard, which means that Maple T.A. can be easily integrated with course management systems that support LTI. Maplesoft officially supports LTI connectivity with Canvas, Blackboard Learn™, Brightspace™, Moodle™, and Sakai.

    Using the LTI standard, you can integrate Maple T.A. directly into your existing course management or learning management platforms. This allows for single-sign on in one central location and Maple T.A. assignment delivery and grade pushing right inside of your existing solutions.

    If you would like to use the LTI connectivity feature, please contact Maplesoft Technical Support at support@maplesoft.com. They will provide the instructions and files you need to set up your connection, and answer any questions you may have about how the integration works on your platform.

    Jonny
    Maplesoft Product Manager, Maple T.A.

    A wealth of knowledge is on display in MaplePrimes as our contributors share their expertise and step up to answer others’ queries. This post picks out one such response and further elucidates the answers to the posted question. I hope these explanations appeal to those of our readers who might not be familiar with the techniques embedded in the original responses.

    Before I begin, a quick note that the content below was primarily created by one of our summer interns, Pia, with guidance and advice from me.

    The Question: Source Code of Math Apps

    Eberch, a new Maple user, was interested in learning how to build his own Math Apps by looking at the source code of some of the already existing Math Apps that Maple offers.

    Acer helpfully suggested that he look into the Startup Code of a Math App, in order to see definitions of procedures, modules, etc. He also recommended Eberch take a look at the “action code” that most of the Math Apps have which consist of function calls to procedures or modules defined in the Startup Code. The Startup Code can be accessed from the Edit menu. The function calls can be seen by right-clicking on the relevant component and selecting Edit Click Action.

    Acer’s answer is correct and helpful. But for those just learning Maple, I wanted to provide some additional explanation.

    Let’s talk more about building your own Math Apps

    Building your own Math Apps can seem like something that involves complicated code and rare commands, but Daniel Skoog perfectly portrays an easy and straightforward method to do this in his latest webinar. He provides a clear definition of a Math App, a step-by-step approach to creating a Math App using the explore and quiz commands, and ways to share your applications with the Maple community. It is highly recommended that you watch the entire webinar if you would like to learn more about the core concepts of working with Maple, but you can find the Math App information starting at the 33:00 mark.

    I hope that you find this useful. If there is a particular question on MaplePrimes that you would like further explained, please let me know. 

    The GroupTheory package in Maple includes facilities for working with finitely presented groups - groups defined by finitely many generators and defining relations.  We now have a video tutorial that covers the basics of this aspect of the package.  As always, we appreciate feedback and suggestions regarding this feature, or new features that you would like to see in the GroupTheory package.

    Maple's dsolve numeric can solve delay ODEs and DAEs as of Maple 18. However, if I am not wrong, it cannot solve delay equations with a time dependent history. In this post I show two examples.

    Example 1:

    y1(t) and y2(t) with time dependent history. Use of piecewise helps this problem to be solved efficiently. Hopefully Maple will add history soon in its capability.

    Example 2: 

    This is a very a complicated stiff problem from immunology. As of now, I believe only Maple can solve this (other than RADAR5 from Prof. Hairer). Details and plots are posted in the attached code.

     

    Let me know if any one has a delay problem that needs to be solved. I have tested many delay problems in Maple (they work fine). The attached examples required addtional tweaking, hence the post.

     

    I want to take this opportunity to congratulate and thank Maple's dsolve numeric/delay solvers for their fantastic job. Maple is world leader not because of example1, but because of its ability to solve example 2.

     

     

    restart;

     This code is written by Dayaram Sonawane and Venkat R. Subramnian, University of Washington. You will need Maple 18 or later for this. For those who are wanting to solve these problems in earlier versions, I can help them by offering a procedure based approach (less efficient).

    Example1 The first example solved is a state dependent delay problem (http://www.mathworks.com/help/matlab/math/state-dependent-delay-problem.html).

     

    eq1:= diff(y1(t),t)=y2(t);

    eq1 := diff(y1(t), t) = y2(t)

    (1)

    eq2:=diff(y2(t),t)=-y2(exp(1-y2(t)))*y2(t)^2*exp(1-y2(t));

    eq2 := diff(y2(t), t) = -y2(exp(1-y2(t)))*y2(t)^2*exp(1-y2(t))

    (2)

     Both y1(t) and y2(t) have time dependent history (y1(t)=log(t) and y2(t)=1/t, t<-0.1). If I am not mistaken one cannot solve this directly using Maple's dsolve numeric command. However, a simple trick can be used to redefine the equations for y1(t) and y2(t) as below

    eq3:=diff(y1(t),t)=piecewise(t<=0.1,1/t,y2(t));

    eq3 := diff(y1(t), t) = piecewise(t <= .1, 1/t, y2(t))

    (3)

    eq4:=diff(y2(t),t)=piecewise(t<=0.1,-1/t^2,-y2(exp(1-y2(t)))*y2(t)^2*exp(1-y2(t)));

    eq4 := diff(y2(t), t) = piecewise(t <= .1, -1/t^2, -y2(exp(1-y2(t)))*y2(t)^2*exp(1-y2(t)))

    (4)

     The problem is solved from a small number close to t = 0 (1e-4) to make Maple's dsolve numeric remember the history till t = 0.1

    epsilon:=1e-4;

    epsilon := 0.1e-3

    (5)

    sol:=dsolve({eq3,eq4,y1(epsilon)=log(epsilon),y2(epsilon)=1/epsilon},type=numeric,delaymax=5):

    with(plots):

    odeplot(sol,[t,y1(t)],0.1..5,thickness=3,axes=boxed);

     

    odeplot(sol,[t,y2(t)],0.1..5,thickness=3,axes=boxed);

     

    sol(5.0);log(5.0);1/5.0;

    [t = 5.0, y1(t) = 1.60942323180838, y2(t) = .199998786891688]

    1.609437912

    .2000000000

    (6)

    Tweaking the tolerances and epsilon will get the solution even more closer to the expected answers.

     

     

     Example 2

     The next problem discussed is very stiff, complicated and as of today, according Professor Hairer (one of the world's leading authority in numerical solutions of ODEs, DAEs), cannot be solved by any other code other than his RADAR (5th order implicit Runge Kutta modified for delay equations, Guglielmi N. and Hairer E. (2001) Implementing Radau IIa methods for stiff delay differential equations. Computing 67:1-12). This problem requires very stringent tolerances. For more information read, http://www.scholarpedia.org/article/Stiff_delay_equations. I can safely say that Maple can boast that it can solve this delay differential equation by using a switch function (instead of Heaviside/picecewise function). Code is attached below and results are compared with the output from RADAR code.  Note that dsolve/numeric is probably taking more time steps compared to RADAR, but the fact that Maple's dsolve numeric solved this model (which cannot be solved in Mathematica or MATLAB[needs confirmation for MATLAB]) should make Maple's code writers proud. It is very likely that we will be trying to submit an educational/research article on this topic/example soon to a journal. For some weird reasons, stiff=true gives slightly inaccurate results.

    restart:

     

    radar5data:=readdata("C:\\Users\\Venkat16core-office\\Google Drive\\waltmanproblem\\sol.txt",[string,string,float,string,string,float,float,float,float,float,float]):

    nops(radar5data);

    1059

    (7)

    radar5data[1059];

    ["X", "=", 300.000000, "Y", "=", 0.6154486288e-15, 0.3377120916e-6, 0.4221403310e-6, 0.2142554563e-5, 299.9999999, 299.6430338]

    (8)

    eq[1]:=diff(y[1](t),t)=-r*y[1](t)*y[2](t)-s*y[1](t)*y[4](t);

    eq[1] := diff(y[1](t), t) = -r*y[1](t)*y[2](t)-s*y[1](t)*y[4](t)

    (9)

    eq[2]:=diff(y[2](t),t)=-r*y[1](t)*y[2](t)+alpha*r*y[1](y[5](t))*y[2](y[5](t))*H1;#Heaviside(t-35);

    eq[2] := diff(y[2](t), t) = -r*y[1](t)*y[2](t)+alpha*r*y[1](y[5](t))*y[2](y[5](t))*H1

    (10)

    eq[3]:=diff(y[3](t),t)=r*y[1](t)*y[2](t);

    eq[3] := diff(y[3](t), t) = r*y[1](t)*y[2](t)

    (11)

    eq[4]:=diff(y[4](t),t)=-s*y[1](t)*y[4](t)-gamma1*y[4](t)+beta*r*y[1](y[6](t))*y[2](y[6](t))*H2;#Heaviside(t-197);

    eq[4] := diff(y[4](t), t) = -s*y[1](t)*y[4](t)-gamma1*y[4](t)+beta*r*y[1](y[6](t))*y[2](y[6](t))*H2

    (12)

    eq[5]:=diff(y[5](t),t)=H1*(y[1](t)*y[2](t)+y[3](t))/(y[1](y[5](t))*y[2](y[5](t))+y[3](y[5](t)));#eq[7]:=y[7](t)=HH(t);

    eq[5] := diff(y[5](t), t) = H1*(y[1](t)*y[2](t)+y[3](t))/(y[1](y[5](t))*y[2](y[5](t))+y[3](y[5](t)))

    (13)

    eq[6]:=diff(y[6](t),t)=H2*(10.^(-12)*0+y[2](t)+y[3](t))/(10.^(-12)*0+y[2](y[6](t))+y[3](y[6](t)));

    eq[6] := diff(y[6](t), t) = H2*(y[2](t)+y[3](t))/(y[2](y[6](t))+y[3](y[6](t)))

    (14)

    H1:=1/2+1/2*tanh(100*(t-35));H2:=1/2+1/2*tanh(100*(t-197));

    H1 := 1/2+(1/2)*tanh(100*t-3500)

    H2 := 1/2+(1/2)*tanh(100*t-19700)

    (15)

    alpha:=1.8;beta:=20.;gamma1:=0.002;r:=5.*10^4;s:=10.^5;

    alpha := 1.8

    beta := 20.

    gamma1 := 0.2e-2

    r := 50000.

    s := 100000.

    (16)

    seq(eq[i],i=1..6);

    diff(y[1](t), t) = -50000.*y[1](t)*y[2](t)-100000.*y[1](t)*y[4](t), diff(y[2](t), t) = -50000.*y[1](t)*y[2](t)+90000.0*y[1](y[5](t))*y[2](y[5](t))*(1/2+(1/2)*tanh(100*t-3500)), diff(y[3](t), t) = 50000.*y[1](t)*y[2](t), diff(y[4](t), t) = -100000.*y[1](t)*y[4](t)-0.2e-2*y[4](t)+1000000.*y[1](y[6](t))*y[2](y[6](t))*(1/2+(1/2)*tanh(100*t-19700)), diff(y[5](t), t) = (1/2+(1/2)*tanh(100*t-3500))*(y[1](t)*y[2](t)+y[3](t))/(y[1](y[5](t))*y[2](y[5](t))+y[3](y[5](t))), diff(y[6](t), t) = (1/2+(1/2)*tanh(100*t-19700))*(y[2](t)+y[3](t))/(y[2](y[6](t))+y[3](y[6](t)))

    (17)

    ics:=y[1](0)=5.*10^(-6),y[2](0)=10.^(-15),y[3](0)=0,y[4](0)=0,y[5](0)=1e-40,y[6](0)=1e-20;

    ics := y[1](0) = 0.5000000000e-5, y[2](0) = 0.1000000000e-14, y[3](0) = 0, y[4](0) = 0, y[5](0) = 0.1e-39, y[6](0) = 0.1e-19

    (18)

    #infolevel[all]:=10;

    sol:=dsolve({seq(eq[i],i=1..6),ics},type=numeric,delaymax=300,initstep=1e-6,abserr=[1e-21,1e-21,1e-21,1e-21,1e-9,1e-9],[y[1](t),y[2](t),y[3](t),y[4](t),y[5](t),y[6](t)],relerr=1e-9,maxstep=10,optimize=false,compile=true,maxfun=0):

     

     

     note that compile = true was used for efficiency

    t11:=time():sol(300);time()-t11;

    [t = 300., y[1](t) = 0.615611371327094e-15, y[2](t) = 0.337706811581908e-6, y[3](t) = 0.422136411682798e-6, y[4](t) = 0.214253771204037e-5, y[5](t) = 299.999986716780, y[6](t) = 299.643054284209]

    .141

    (19)

    with(plots):

    nd:=nops(radar5data);

    nd := 1059

    (20)

    radar5data[nd];

    ["X", "=", 300.000000, "Y", "=", 0.6154486288e-15, 0.3377120916e-6, 0.4221403310e-6, 0.2142554563e-5, 299.9999999, 299.6430338]

    (21)

     Values at t = 300 match with expected results.

    pr[1]:=plot([seq([radar5data[i][3],log(radar5data[i][6])/log(10)],i=1..nd)],style=point,color=green):

    p[1]:=odeplot(sol,[t,log(y[1](t))/log(10)],0..300,axes=boxed,thickness=3):

    display({pr[1],p[1]});

     

    pr[2]:=plot([seq([radar5data[i][3],log(radar5data[i][7])/log(10)],i=1..nd)],style=point,color=green):

    p[2]:=odeplot(sol,[t,log(y[2](t))/log(10)],0..300,axes=boxed,thickness=3,numpoints=1000):

    display({pr[2],p[2]});

     

    pr[3]:=plot([seq([radar5data[i][3],log(radar5data[i][8])/log(10)],i=2..nd)],style=point,color=green):

     

    p[3]:=odeplot(sol,[t,log(y[3](t))/log(10)],0..300,axes=boxed,thickness=3):

    display({pr[3],p[3]});

     

    pr[4]:=plot([seq([radar5data[i][3],log(radar5data[i][9])/log(10)],i=496..nd)],style=point,color=green,view=[197..300,-9..-5]):

    p[4]:=odeplot(sol,[t,log(y[4](t))/log(10)],197..300,axes=boxed,thickness=3,view=[197..300,-9..-5]):

    display({pr[4],p[4]});

     

    pr[5]:=plot([seq([radar5data[i][3],radar5data[i][10]],i=1..nd)],style=point,color=green):

    p[5]:=odeplot(sol,[t,y[5](t)],0..300,axes=boxed,thickness=3):

    display({pr[5],p[5]});

     

    pr[6]:=plot([seq([radar5data[i][3],radar5data[i][11]],i=1..nd)],style=point,color=green):

    p[6]:=odeplot(sol,[t,y[6](t)],0..300,axes=boxed,thickness=3):

    display({pr[6],p[6]});

     


    Download delayimmunetopost.mws

    As a very good application for viewing and calculation of the components of acceleration either tangential or normal. Besides immediately it is shown an Application for physics.

    Componentes_de_la_Acelelación.mw

    (in spanish)

    L. Araujo C.

     

     

    Here we see the projection of a vector onto another using different concepts ranging from linear algebra to vector calculus. Implemented components thus seen in three-dimensional space.

     

    Proyecciones_Vectoriales.mw

    (in spanish)

    L.Araujo C.

    Bryon, since you are the mapleprimes.com programmer I am requesting that you add replies to the users list.  They are not brought up under users answers.

    We have see all posts by... see all questions by... and see all answers by... however those categories miss every reply posted by the user.

    Maple 2015 has a new command, dataplot, for plotting datasets. It was designed to be easy to use and it offers several new features that are not available in Maple's other plotting commands. A few months ago, I recorded a video that gives an overview of the command. If you have any questions or comments about dataplot, feel free to post here. I'm also including the worksheet that is shown in the video: DataplotWebinar.mw

    Maple’s Code Generation makes it possible to translate your Maple code to various other programming languages including C, Python, and several others. In Maple 2015, we added a new Code Generation target to one of my other personal favourite languages, R. R is a programming language designed for statistical computing and graphics, so no code translation from Maple to R would be complete without attempting to translate as many commands as possible from Maple’s Statistics package. 

    Translating code from one language to another is tricky business. Maple 2015 represented the first time that any Code Generation target language added the ability to translate commands from the Statistics package. With R, we found that many common statistics commands had almost a one-to-one mapping, such as Statistics:-Mean = mean, but several others were much more complicated, including several commands for dealing with probability functions that did not have direct mappings due to differences in how the systems handle symbolic probability functions.

    A list of statistics commands that can be translated from Maple to R can be found here.

    In addition to assisting me recall the correct syntax in R, having worked with CodeGeneration[R] for several months now, I find that one of my most common uses for Maple’s code generation to R is simply to pass data between the systems. A simple example:

     CodeGeneration:-R( LinearAlgebra:-RandomMatrix( 5, 2 ) );

    translates to the following in R:

     cg <- matrix(c(-4,27,8,69,99,29,44,92,-31,67),nrow=5,ncol=2)

    To see a couple more short examples, here’s a short video that I recorded on Code Generation to R:

    A little known fact about Code Generation is that the translation files can be viewed in from the “samples” directory in your Maple install directory. Similar to many of Maple’s packages, you can view all of the source code that Code Generation uses for its translations. For example, you can view the translations for the commands that I mentioned above from the “FunctionTable.mm” file inside of your “%MapleInstallDir%/ samples/CodeGeneration/R” directory.

    Should you have any feedback on this translation, or any other, please feel free to contact us. We’re also on the hunt for our next code generation targets, so let us know what other languages you would like to see added as Code Generation targets.

    A wealth of knowledge is on display in MaplePrimes as our contributors share their expertise and step up to answer others’ queries. This post picks out one such response and further elucidates the answers to the posted question. I hope these explanations appeal to those of our readers who might not be familiar with the techniques embedded in the original responses.

    Before I begin, a quick note that the content below was primarily created by one of our summer interns, Pia, with guidance and advice from me.

    MaplePrimes member Thomas Dean wanted 1/2*x^(1/2) + 1/13*x^(1/3) + 1/26*x^(45/37)  to become  0.5*x^0.500000 + 0.07692307692*x^0.333333 + 0.03846153846*x^1.216216216  using the evalf command.

    Here you can see the piece of code that Thomas Dean wrote in Maple:

    eq:=1/2*x^(1/2) + 1/13*x^(1/3) + 1/26*x^(45/37);
    evalf(eq);

    Carl Love replied simply and effectively with a piece of code, using the evalindets command instead:

    evalindets(eq, fraction, evalf);

    As always, Love provided an accurate response, and it is absolutely correct. But for those just learning Maple, I wanted to provide some additional explanation.

    The evalindets command, evalindets( expr, atype, transformer, rest ), is a particular combination of calls to eval and indets that allows you to efficiently transform all subexpressions of a given type by some algorithm. It encapsulates a common "pattern" used in expression manipulation and transformation.

    Each subexpression of type atype is transformed by the supplied transformer procedure. Then, each subexpression is replaced in the original expression, using eval, with the corresponding transformed expression.

     

    Note: the parameter restis an optional expression sequence of extra arguments to be passed to transformer. In this example it was not used.

    I hope that you find this useful. If there is a particular question on MaplePrimes that you would like further explained, please let me know. 

    I happen to just have a look at mathematica's imagedeconvolve function http://reference.wolfram.com/language/ref/ImageDeconvolve.html .  I had a look at the Examples and saw how a very blurred image of Neil Armstrong standing on the moon with the lunar lander was deconvolved into some really amazing detail. 

    I don't believe that image could deconvolve into what they show on that page, It's somewhat misleading.

    The only way that deconvolved image could have such great detail is the blurred image used was most likely convolved from the detailed image.  

    Here the potential of maple 2015 to the quantitative study of the decomposition of a vector table is shown in two dimensions. Application for the exclusive use of engineering students, which was implemented with embedded components.

    Atte.

    Lenin Araujo Castillo

    Archivo Corregido:  Decomposición_Vectorial_Corregido.mw

    LL_104)_NASDAQ.mw
    Portfolio_Optimization.txt

    Portfolio Optimization with Google Spreadsheet and Maple
     

    I will in this post show how to manage data and do portfolio optimization in Maple by using google spreadsheet.

    You can either use a direct link to the data:

    https://docs.google.com/spreadsheets/d/1L5-yUB0EWeBdJNMdELKBRmBQ1JJ0QymrtDLkVhHCVn8/pub?gid=649021574&single=true&output=csv

    or you can set up your own google spreadsheet. If you choice to set up your own spreedsheet follow the below road map:

    1) select which market you want to follow:

    NASDAQ

    http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NASDAQ&render=download

    NYSE

    http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NYSE&render=download

    AMEX

    http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=AMEX&render=download


    2) Create a new google spreadsheet and name two sheets Blad1 and Panel. In the first cell of Blad1 you put the formula:

    =IMPORTDATA("http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NASDAQ&render=download")

    you need to change the url to match your selection in 1).


    3) In the first cell of Panel you put the name "Ticker" and then you copy all the ticker names from Blad1.

    4) In the script editor you put in the below java script code:


    function PanelCreation_Stock() 

    {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sourceSheet = ss.getSheetByName("Blad1");
    var dstSheet = ss.getSheetByName("Panel");
    var curDat = new Date();
    var day1 = curDat.getDay();
    if(day1 == 0 || day1 == 1)
    {
    return;
    }
    var lCol = dstSheet.getLastColumn();
    var srcdate = dstSheet.getRange(1, 1, 1, lCol).getValues();

    for(var k=1;k<=srcdate[0].length-1;k++)
    {
    if(Utilities.formatDate(srcdate[0][k],"GMT", "dd-MMM-yy") == Utilities.formatDate(curDat,"GMT", "dd-MMM-yy"))
    {
    return;
    }
    }
    var snRows = sourceSheet.getLastRow();
    var dnRows = dstSheet.getLastRow();

    var srcStock = sourceSheet.getRange("A2:A" + snRows).getValues();
    var srcLastSale = sourceSheet.getRange("C2:C" + snRows).getValues();

    var dstStock = dstSheet.getRange("A2:A" + dnRows).getValues();
    var dstLastSale = dstSheet.getRange("Z2:Z" + dnRows).getValues();

    for(var j=0;j<dnRows-1;j++)
    {
    dstLastSale[j][0]="n/a";
    }
    var flag = "true";
    var foundStock;
    for(var i=0;i<snRows-1;i++) //snRows
    {
    var sStockVal = srcStock[i][0];

    //var foundStock = ArrayLib.indexOf(dstStock,0, sStockVal);

    flag="false";
    for(var j=0;j<dnRows-1;j++)
    {
    if(dstStock[j][0].toString().toUpperCase() == srcStock[i][0].toString().toUpperCase())
    {
    flag = "true";
    foundStock = j;
    break;
    }
    }
    if(flag=="true")
    {
    dstLastSale[foundStock][0] = srcLastSale[i][0];
    }
    else
    {
    var dnRows1 = dstSheet.getLastRow()+1;
    dstSheet.getRange("A" + dnRows1).setValue(srcStock[i][0]);
    dstSheet.getRange(dnRows1,lCol+1,1,1).setValue(srcLastSale[i][0]);
    for(var k=2;k<=lCol;k++)
    {
    if(dstSheet.getRange(dnRows1, k).getValue()=="")
    {
    dstSheet.getRange(dnRows1, k).setValue("n/a");
    }
    }
    }
    }
    dstSheet.getRange(1,lCol+1).setValue(curDat);
    dstSheet.getRange(2, lCol+1, dstLastSale.length, 1).setValues(dstLastSale);
    }

     
    5) Set it to run each day at 12:00. The code will save the new last sale price for monday to friday with one days lag.

    Now we can move on to Maple.


    In Maple run the following code to load the data:

     

    X := proc (Url) local theDLL, URLDownloadToFile, myDirectory, myFile, Destination, DL;

     

    theDLL := "C:\\WINDOWS\\SYSTEM32\\urlmon.dll";

     

    URLDownloadToFile := define_external('URLDownloadToFileA', pCaller::(integer[4]), szURL::string, szFileName::string, dwReserved::(integer[4]), lpfnCB::(integer[4]), 'RETURN'::(integer[4]), LIB = theDLL);

     

    if FileTools[Exists]("C:\\mydir") = true then FileTools:-RemoveDirectory("C:\\mydir", recurse = true, forceremove = true) else end if;

     

    FileTools:-MakeDirectory("C:\\mydir");
    myDirectory := "C:\\mydir";
    myFile := "data1.csv";
    Destination := cat(myDirectory, "\\", myFile);

     

    DL := proc () local M;

     

    URLDownloadToFile(0, Url, Destination, 0, 0);
    M := ImportMatrix("C:\\mydir\\data1.csv", delimiter = ",", datatype = string);
    M := Matrix(M, datatype = anything)

     

    end proc;

     

    return DL()

     

    end proc:

     

    data := X("https://docs.google.com/spreadsheets/d/1L5-yUB0EWeBdJNMdELKBRmBQ1JJ0QymrtDLkVhHCVn8/pub?gid=649021574&single=true&output=csv");
    L := LinearAlgebra:-Transpose(data);

    If you use your own spreadsheet you need to change the url to match that spreadsheet.
    Select File -> Publish to the web in google spreadsheet

    We can now run the portfolio optimization in Maple:

    with(Statistics):
    with(ListTools):
    with(LinearAlgebra):
    with(Optimization):
    with(plots):

     

    Nr, Nc := ArrayTools:-Size(L):
    symb := L[1 .. 1, 2 .. Nc]:
    LL := L[2 .. Nr, 2 .. Nc]:
    Nr, Nc := ArrayTools:-Size(LL):

     

    # Removing stocks with missing observations
    for i to Nc do if Occurrences("n/a", convert(Column(LL, i), list)) >= 1 then AA[i] := i else AA[i] := 0 end if
    end do;

     

    DD := RemoveInRange([seq(AA[i], i = 1 .. Nc)], 0 .. 1):
    symbb := DeleteColumn(symb, DD):
    LLL := map(parse, DeleteColumn(LL, DD)):
    Nr, Nc := ArrayTools:-Size(LLL):

     

    # Calculate Return
    for j to Nc do
    for i from 2 to Nr do

     

    r[i, j] := (LLL[i, j]-LLL[i-1, j])/LLL[i-1, j]

     

    end do
    end do;

     

    RR := Matrix([seq([seq(r[i, j], j = 1 .. Nc)], i = 2 .. Nr)], datatype = float[8]);
    n, nstock := ArrayTools:-Size(RR):

     

    # Portfolio Optimization
    W := Vector(nstock, symbol = w):
    y := Vector(n, fill = 2, datatype = float[8]):
    s1 := Optimization[LSSolve]([y, RR])[2];
    Nr, Nc := ArrayTools:-Size(s1):

     

    j := 0:
    for i to Nr do if s1[i] <> 0 then j := j+1; ss1[j] := symbb[1, i] = s1[i] end if end do;

     

    Vector(j, proc (i) options operator, arrow; ss1[i] end proc);
    LineChart(s1);

     

     

     

    First 75 76 77 78 79 80 81 Last Page 77 of 307