Alec Mihailovs

Dr. Aleksandrs Mihailovs

4455 Reputation

21 Badges

20 years, 311 days
Mihailovs, Inc.
Owner, President, and CEO
Tyngsboro, Massachusetts, United States

Social Networks and Content at Maplesoft.com

I received my Ph.D. from the University of Pennsylvania in 1998 and I have been teaching since then at SUNY Oneonta for 1 year, at Shepherd University for 5 years, at Tennessee Tech for 2 years, at Lane College for 1 year, and this year I taught at the University of Massachusetts Lowell. My research interests include Representation Theory and Combinatorics.

MaplePrimes Activity


These are answers submitted by Alec Mihailovs

Trying the example in the original post, I got an error, since printf has 3 %a and only 2 substitutions for them.

Alec

In Sage it is as simple as (an example from David Joyner's post)

sage: P1 = plot(sin(x), (x,-pi,pi))
sage: P2 = text("$y=\sin(x),\ -\pi\leq x\leq \pi$", (1.5,4)) 
sage: p=P1+P2
sage: p.save("sin.png")

Alec

A general system of 5 equations with 8 unknowns has 3-dimensional variety of solutions, infinite number of them, so such an approach with allvalues and evalf may be not appropriate. It is hard to tell without seeing the system.

There are better methods for some classes of systems, such as systems of linear equations, for example.

Alec

For example,

eval(y,solve({y=a*10^(x/20)+b*10^(x/10),10^(x/20)=K},{y,x}));
                                       2
                              a K + b K

Alec

ExcelTools:-Import can be used for importing data from Excel.

Alec

It has appeared to be not that hard,

infnorm:=N->subs(20=N, op(numapprox:-infnorm))(_rest);

infnorm(100, sin(1000*Pi*x),x=0..1);

                                  1.

Digits:=14:

infnorm(1000,g(x),x=0..1);

                             736225.73653657

infnorm(5000.,g(x),x=0..1);

                           736225.83968580

That took rather long time though. Seems to be a good testing example.

I learned this trick from Joe Riel's post and I am glad to thank him for that.

Alec

It is interesting, how to patch that. The simple way

infnorm:=N->parse(
    StringTools:-Substitute(
        sprintf("%a",eval(numapprox:-infnorm)),
        "20",
        sprintf("%d",N)))(_rest);

works in the sin example,

infnorm(100, sin(1000*Pi*x),x=0..1);
Warning, `infnormN` is implicitly declared local to procedure

                                  1.

with a warning, but giving the correct answer. However, even large values of N give the following for g(x)

infnorm(100000,g(x),x=0..1);
Warning, `infnormN` is implicitly declared local to procedure

           infnorm1(one, fproc, zero, 0., 1., 100000, arr)

Alec

Looking at showstat(numapprox:-infnorm) it seems as if epsilon is cotrolled by Digits.

From the first view, it looks as if calculations are done using evalhf, and the evalhf restricted precision may be not good enough in this example, because of the following,

fsolve(diff(g(x),x),x=0..1);
                             0.9996702595
g(%);
                             -736225.8400
g(1.);
                                0.001

Alec

GenerateMatrix can be used, just with a slight twist. The direct using of it adds negative signs,

s:={diff(x(t),t)=a*x(t)+b*y(t),diff(y(t),t)=c*x(t)+d*y(t)};

LinearAlgebra:-GenerateMatrix(s,[x(t),y(t)]);

                                   [ /d      \]
                                   [-|-- x(t)|]
                       [-a    -b]  [ \dt     /]
                       [        ], [          ]
                       [-c    -d]  [ /d      \]
                                   [-|-- y(t)|]
                                   [ \dt     /]

so the signs need to be inverted,

eval(-(LinearAlgebra:-GenerateMatrix(s,[x(t),y(t)])));

                                   [d      ]
                                   [-- x(t)]
                         [a    b]  [dt     ]
                         [      ], [       ]
                         [c    d]  [d      ]
                                   [-- y(t)]
                                   [dt     ]

After that, ExportMatrix can be used, as usual.

Alec

It doesn't look iterative. Anyway, one can interpolate B as a function of Y, then find solutions for given values of A, and interpolate them for corresponding values of t. For example, using splines,

t:= [ 0.05,0.1,0.2,0.5,1,2,5,10];
A:=[0.9,0.75,0.6,0.2,0.08,0.06,0.051,0.05];
Y:=[25,50,75,100,125,150,175,200,225,400,500,700,1000];
B:=[3250,2500,2000,1725,1550,1400,1325,1275,1225,950,850,775,775];
b:=unapply(CurveFitting:-Spline(Y,B,y),y);
R:=[seq(fsolve(y=A[i]*b(y)),i=1..nops(A))];
sol:=unapply(CurveFitting:-Spline(t,R,T),T);

The result doesn't look very nice though, see

plot(sol,0..10);

Alec

The code in the original post worked OK for me after replacing 2Pi with 2*Pi.

Alec

LOL. Posting at the same time almost identical procedures was fun. The time on the site seems to be about a half an hour off though.

Alec

For example,

inc:=(e::uneval)->assign(map(x->x=eval(x)+1,e)):
 
x,y:=10,20;
                            x, y := 10, 20
inc([x,y]);
x,y;
                                11, 21

Alec

That's strange. At least int(exp(z cos(t)),t=0..2*Pi) should be in the table of known integrals (if such a table exists). Then original integral could be calculated using transformation x cos(t) + y sin(t) = z cos(t-a) with z=sqrt(x^2+y^2), assuming that x and y are real, and noticing that it is an integral over a period allows to get rid of a.

Besides, it can be integrated by expanding exp as power series and integrating the series terms.

Alec

Also, plots[complexplot3d] can be used.

Alec

First 47 48 49 50 51 52 53 Last Page 49 of 76