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
  • 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);

     

     

     

    Here are some tips and tricks - ranging from keyboard shortcuts to the newest features - that will help you get the most out of MapleSim 2015.

    1. Quickly run your simulation by pressing F5. Similarly, toggle between the Main Window and Visualization Window by press F6.

    2. Maintaining an organized and clean model layout is made easier by using the Reroute Connections tool. Select the connection lines or components and press CTRL+D (or using the Edit menu, Reroute Connections) to have MapleSim automatically reroute the connections.

    3. While creating your MapleSim model, components and connections can be enabled or disabled by selecting the desired item(s) and using the disable/enable button (  ) or the keyboard shortcut CTRL+E.

    4. Use the Model Tree palette in MapleSim to help manage, navigate, and search a model quickly. Items within the model tree include: components, probes, parameters, and attachments. Simply select the desired view using the drop-down menu. The Model Tree palette is found under the Project tab.

    5. Automatically remove any unreferenced subsystems or custom components using the Prune Model tool. Especially useful for large models or models with multiple modifications, this tool will automatically identify and removes unused shared subsystems or custom components that appear within the Definitions tab, Components palette. The Prune Model function can be performed by clicking the Edit menu, and selecting Prune Model.

    6. Set the MapleSim’s Visualization Window to always on top by toggling the anchor button (  ) in the upper left corner of the Visualization Window.

    7. Automatically scale the model diagram to fit in the viewable area by pressing CTRL+T to gain a complete look at the model. Then return to a default zoom by pressing CTRL+0 (zero). This is also accessible using the View menu.

    8. To group components into a subsystem, select the desired components, right-click and select Create Subsystem or press CTRL+G.

    9. For quick access to get help on a particular component, right-click on it and select help. Similarly, selecting a component within the workspace and pressing F2 will bring up the help page for that component.

    10. View the Modelica code behind the visible system/subsystem/component, click Code View (  ) in the Navigation Tool bar. Then, to switch back to Diagram Mode click the icon (  ) in the Navigation Tool bar.

    11. Automatically compare two models by using the compare tool, found under the Tools menu Compare Models.

    12. Attach important files to a MapleSim model to keep content in one place. Attachments can be Maple worksheets or others such as pdfs, Excel, Word, STL files, etc. These files are found under the Project Tab, Attachments palette. Attach a file by, right-clicking the category and selecting Attach File or clicking the Edit menu Attach File.

    I hope you find these useful! Do you have any tips that you would add to this list?


    The PDE & BC project , a very nice and challenging one, also one where Maple is pioneer in all computer algebra systems, has restarted, including now also the collaboration of Katherina von Bülow.

    Recapping, the PDE & BC project started 5 years ago implementing some of the basic methods found in textbooks to match arbitrary functions and constants to given PDE boundary conditions of different kinds. At this point we aim to fill gaps, and the first one we tackled is the case of 1st order PDE that can be solved without boundary conditions in terms of an arbitrary function, and where a single boundary condition (BC) is given for the PDE unknown function, and this BC does not depend on the independent variables of the problem. It looks simple ... It can be rather tricky though. The method we implemented is a simple however ingenious use of differential invariants  to match the boundary condition.


    The resulting new code, the portion already tested, is available for download in the Maplesoft R&D webpage for Differential Equations and Mathematical Functions (the development itself is bundled within the library that contains the new developments for the Physics package, in turn within the zip linked in the webpage).


    The examples that can now be handled, although restricted in generality to "only one 1st order linear or nonlinear PDE and only one boundary condition for the unknown function itself", illustrate well how powerful it can be to use more advanced methods to tackle these tricky situations where we need to match an arbitrary function to a boundary condition.


    To illustrate the idea, consider first a linear example, among the simplest one could imagine:

    PDEtools:-declare(f(x, y, z))

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

    (1)

    pde := diff(f(x, y, z), x)+diff(f(x, y, z), y)+diff(f(x, y, z), z) = f(x, y, z)

    diff(f(x, y, z), x)+diff(f(x, y, z), y)+diff(f(x, y, z), z) = f(x, y, z)

    (2)

    Input now a boundary condition (bc) for the unknownf(x, y, z) such that this bc does not depend on the independent variables {x, y, z}; this bc can however depend on arbitrary symbolic parameters, for instance

    bc := f(alpha+beta, alpha-beta, 1) = alpha*beta

    f(alpha+beta, alpha-beta, 1) = alpha*beta

    (3)

    With the recent development, this kind of problem can now be solved in one go:

    sol := pdsolve([pde, bc])

    f(x, y, z) = (1/4)*(x-2*z+2+y)*(x-y)*exp(z-1)

    (4)

    Nice! And how do you verify this result for correctness? With pdetest , which actually also tests the solution against the boundary conditions:

    pdetest(sol, [pde, bc])

    [0, 0]

    (5)

    And what has been done to obtain the solution (4)? First the PDE was solved regardless of the boundary condition, so in general, obtaining:

    pdsolve(pde)

    f(x, y, z) = _F1(-x+y, -x+z)*exp(x)

    (6)

    In a second step, the arbitrary function _F1(-x+y, -x+z) got determined such that the boundary condition f(alpha+beta, alpha-beta, 1) = alpha*beta is matched. Concretely, the mapping _F1 is what got determined. You can see this mapping reversing the solving process in two steps. Start taking the difference between the general solution (6) and the solution (4) that matches the boundary condition

    (f(x, y, z) = _F1(-x+y, -x+z)*exp(x))-(f(x, y, z) = (1/4)*(x-2*z+2+y)*(x-y)*exp(z-1))

    0 = _F1(-x+y, -x+z)*exp(x)-(1/4)*(x-2*z+2+y)*(x-y)*exp(z-1)

    (7)

    and isolate here _F1(-x+y, -x+z)

    PDEtools:-Solve(0 = _F1(-x+y, -x+z)*exp(x)-(1/4)*(x-2*z+2+y)*(x-y)*exp(z-1), _F1(-x+y, -x+z))

    _F1(-x+y, -x+z) = (1/4)*exp(-x+z-1)*(x^2-2*x*z-y^2+2*y*z+2*x-2*y)

    (8)

    So this is the value _F1(-x+y, -x+z) that got determined. To see now the actual solving mapping _F1, that takes for arguments -x+y and -x+z and returns the right-hand side of (8), one can perform a change of variables introducing the two parameters `&tau;__1` and `&tau;__2` of the _F1 mapping:

    {tau__1 = -x+y, tau__2 = -x+z, tau__3 = z}

    {tau__1 = -x+y, tau__2 = -x+z, tau__3 = z}

    (9)

    solve({tau__1 = -x+y, tau__2 = -x+z, tau__3 = z}, {x, y, z})

    {x = -tau__2+tau__3, y = -tau__2+tau__1+tau__3, z = tau__3}

    (10)

    PDEtools:-dchange({x = -tau__2+tau__3, y = -tau__2+tau__1+tau__3, z = tau__3}, _F1(-x+y, -x+z) = (1/4)*exp(-x+z-1)*(x^2-2*x*z-y^2+2*y*z+2*x-2*y), proc (u) options operator, arrow; simplify(u, size) end proc)

    _F1(tau__1, tau__2) = -(1/4)*exp(tau__2-1)*tau__1*(tau__1-2*tau__2+2)

    (11)

    So the solving mapping _F1 is

    _F1 = unapply(rhs(_F1(tau__1, tau__2) = -(1/4)*exp(tau__2-1)*tau__1*(tau__1-2*tau__2+2)), tau__1, tau__2)

    _F1 = (proc (tau__1, tau__2) options operator, arrow; -(1/4)*exp(tau__2-1)*tau__1*(tau__1-2*tau__2+2) end proc)

    (12)

    Wow! Although this pde & bc problem really look very simple, this solution (12) is highly non-obvious, as is the way to get it just from the boundary condition f(alpha+beta, alpha-beta, 1) = alpha*beta and the solution (6) too. Let's first verify that this mapping is correct (even when we know, by construction, that it is correct). For that, apply (12) to the arguments of the arbitrary function and we should obtain (8)

    (_F1 = (proc (tau__1, tau__2) options operator, arrow; -(1/4)*exp(tau__2-1)*tau__1*(tau__1-2*tau__2+2) end proc))(-x+y, -x+z)

    _F1(-x+y, -x+z) = -(1/4)*exp(-x+z-1)*(-x+y)*(x-2*z+2+y)

    (13)

    Indeed this is equal to (8)

    normal((_F1(-x+y, -x+z) = -(1/4)*exp(-x+z-1)*(-x+y)*(x-2*z+2+y))-(_F1(-x+y, -x+z) = (1/4)*exp(-x+z-1)*(x^2-2*x*z-y^2+2*y*z+2*x-2*y)))

    0 = 0

    (14)

    Skipping the technical details, the key observation to compute a solving mapping is that, given a 1st order PDE where the unknown depends on k independent variables, if the boundary condition depends on k-1 arbitrary symbolic parameters alpha, beta, one can always seek a "relationship between these k-1parameters and the k-1differential invariants that enter as arguments in the arbitrary function _F1 of the solution", and get the form of the mapping _F1 from this relationship and the bc. The method works in general. Change for instance the bc (3) making its right-hand side be a sum instead of a product

    bc := f(alpha+beta, alpha-beta, 1) = alpha+beta

    f(alpha+beta, alpha-beta, 1) = alpha+beta

    (15)

    sol := pdsolve([pde, bc])

    f(x, y, z) = (x-z+1)*exp(z-1)

    (16)

    pdetest(sol, [pde, bc])

    [0, 0]

    (17)

    An interesting case happens when the boundary condition depends on less than k-1 parameters, for instance:

    bc__1 := subs(beta = alpha, bc)

    f(2*alpha, 0, 1) = 2*alpha

    (18)

    sol__1 := pdsolve([pde, bc__1])

    f(x, y, z) = ((x-z+1)*_C1+x-y)*exp(((z-1)*_C1+y)/(1+_C1))/(1+_C1)

    (19)

    As we see in this result, the additional difficulty represented by having few parameters got tackled by introducing an arbitrary constant _C1 (this is likely to evolve into something more general...)

    pdetest(sol__1, [pde, bc__1])

    [0, 0]

    (20)

    Finally, consider a nonlinear example

    PDEtools:-declare(u(x, y))

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

    (21)

    pde := 3*(u(x, y)-y)^2*(diff(u(x, y), x))-(diff(u(x, y), y)) = 0

    3*(u(x, y)-y)^2*(diff(u(x, y), x))-(diff(u(x, y), y)) = 0

    (22)

    Here we have 2 independent variables, so for illustration purposes use a boundary condition that depends on only one arbitrary parameter

    bc := u(0, alpha) = alpha

    u(0, alpha) = alpha

    (23)

    All looks OK, but we still have another problem: check the arbitrary function _F1 entering the general solution of pde when tackled without any boundary condition:

    pdsolve(pde)

    u(x, y) = RootOf(-y^3+3*y^2*_Z-3*y*_Z^2+_Z^3-_F1(_Z)-x)

    (24)

    Remove this RootOf to see the underlying algebraic expression

    DEtools[remove_RootOf](u(x, y) = RootOf(-y^3+3*y^2*_Z-3*y*_Z^2+_Z^3-_F1(_Z)-x))

    -y^3+3*y^2*u(x, y)-3*y*u(x, y)^2+u(x, y)^3-_F1(u(x, y))-x = 0

    (25)

    So this is a pde where the general solution is implicit, actually depending on an arbitrary function of the unknown u(x, y) The code handles this problem in the same way, just that in cases like this there may be more than one solution. For this very particular bc (23) there are actually three solutions:

    pdsolve([pde, bc])

    u(x, y) = x^(1/3)+y, u(x, y) = -(1/2)*x^(1/3)-((1/2)*I)*3^(1/2)*x^(1/3)+y, u(x, y) = -(1/2)*x^(1/3)+((1/2)*I)*3^(1/2)*x^(1/3)+y

    (26)

    Verify these three solutions against the pde and the boundary condition

    map(pdetest, [u(x, y) = x^(1/3)+y, u(x, y) = -(1/2)*x^(1/3)-((1/2)*I)*3^(1/2)*x^(1/3)+y, u(x, y) = -(1/2)*x^(1/3)+((1/2)*I)*3^(1/2)*x^(1/3)+y], [pde, bc])

    [[0, 0], [0, 0], [0, 0]]

    (27)

    :)


    Download PDEs_and_Boundary_Conditions.mw

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

    First 69 70 71 72 73 74 75 Last Page 71 of 301