acer

18951 Reputation

29 Badges

14 years, 276 days

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

You might be making the mistake of using lowercase pi instead of Pi.

If I accidentally use the "Evaluate at a Point" context-menu item and supply lowercase 2*pi as the value for t then I'll get the same result as you. But lowercase pi is just a name, with no special meaning to Maple.

But if I use the capitalized Pi in the "Evaluate at a Point" context-menu item, and supply 2*Pi as the value for t then the output is the expected result.

g := t*(cos(t)+I*sin(t))

t*(cos(t)+I*sin(t))

expr := diff(g, t)

cos(t)+I*sin(t)+t*(-sin(t)+I*cos(t))

"(->)"

1+(2*I)*Pi

eval(expr, t = 2*Pi)

1+(2*I)*Pi

eval(expr, t = 2*pi)

cos(2*pi)+I*sin(2*pi)+2*pi*(-sin(2*pi)+I*cos(2*pi))

evalf(Pi)

3.141592654

evalf(pi)

pi

``

Download Pi_versus_pi.mw

S := -A/Pi*Sum((-1)^k*sin(2*Pi*k*f*(t-Pi/8))/k,k=1..N):

bg := plots:-display(
  plot(fmod(t,Pi/4)*4/Pi-1/2,t=0..Pi,color=blue,thickness=1),
  plots:-pointplot([seq([[i*Pi/4,0.5],[(i-1)*Pi/4,-0.5]][],i=1..4)],
                   symbol=solidcircle,symbolsize=8,color=white),
  plots:-pointplot([seq([[i*Pi/4,0.5],[(i-1)*Pi/4,-0.5]][],i=1..4)],
                   symbol=circle,symbolsize=12,color=blue)):

F := n -> plots:-display(bg,
    plot(eval(S,[A=1,f=4/Pi,:-N=round(n)]),t=0..Pi,
         thickness=1,color=red,numpoints=max(2,10*round(n))),
    plots:-textplot([0.35,-1.0,sprintf("N = %-2ld",round(n))],
                    font=["Monospaced","bold"])):

L := [0$8, 1$8, 2$8, 3$8, $4..49, 50$12]: # delay by repeating
plots:-animate(F,[N],N=L,frames=nops(L),paraminfo=false,
               xtickmarks=[],ytickmarks=[],axis[2]=[color=white],
               axis[1]=[color="#9090FF",thickness=0],size=[600,300],
               labels=[``,``],view=[Pi/16..Pi-Pi/16,-1.25..1.25]);

That is a set

See the set Help page, and in particular its Description section which should make clear the distinction between a list and a set.

When you're looking at a Help page it's often useful to give a quick glance at the "See Also" links. In this case you could also look at the Help pages for topic type/set and selection .

a := {"bar", "foo"}:

whattype(a);
               set

op(0, a);
               set

type(a, set);
               true

type(a, list);
               false

The entries of a set are stored as an expression sequence, which is also true for a list. The main differences are that the set entries are uniquified (duplicates removed) and reordered automatically, while list enties can have duplicates and are stored in a specified order.

op(a);
            "bar", "foo"

{"bar", "foo"};
           {"bar", "foo"}

{"foo", "bar", "foo"};
           {"bar", "foo"}

["bar", "foo"];
           ["bar", "foo"]

["foo", "bar", "foo"];
         ["foo", "bar", "foo"]

If you are looking to plot the integral against a variable upper limit of integration then these compute very quickly.

restart

expr := 2*sqrt((a^2+1)/(x^2+1))/sqrt((x^2+1)*exp(4*m*(arctan(a)-arctan(x)))-a^2-1)

pars := [m = 1, a = 3]

F := subs(integrand = unapply(eval(expr, pars), x), proc (X) options operator, arrow; evalf(Int(integrand, eval(a, pars) .. X, method = `if`(X = infinity, _d01amc, _d01ajc), epsilon = 0.1e-6)) end proc)

proc (X) options operator, arrow; evalf(Int(proc (x) options operator, arrow; 2*10^(1/2)*(1/(x^2+1))^(1/2)/((x^2+1)*exp(4*arctan(3)-4*arctan(x))-10)^(1/2) end proc, eval(a, pars) .. X, method = `if`(X = infinity, _d01amc, _d01ajc), epsilon = 0.1e-6)) end proc

F(4), F(infinity)

2.488627376, 5.507527357

plot([F, F(infinity)], 3 .. 200)

plot([F, F(infinity)], 3 .. 10^3, axis[1] = [mode = log])

plot([F, F(infinity)], 3 .. infinity)

 

Download integral_test_ac.mw

Here are two approaches, the first of which does not need Digits raised high, and is pretty quick and not very complicated. Neither is terribly slow. Do the results concur with your expectation?

Were you hoping to see some explicit rearrangement of terms, so that avoiding numeric difficulties (roundoff and loss of precision, say) were more transparent?

I used Maple 16.02.

restart

Digits := 20

20

y1 := C1[1, 1]*sin(alpha*x)+C1[1, 2]*cos(alpha*x)+C1[1, 3]*sinh(beta*x)+C1[1, 4]*cosh(beta*x)

C1[1, 1]*sin(alpha*x)+C1[1, 2]*cos(alpha*x)+C1[1, 3]*sinh(beta*x)+C1[1, 4]*cosh(beta*x)

y2 := C1[2, 1]*sin(alpha*x)+C1[2, 2]*cos(alpha*x)+C1[2, 3]*sinh(beta*x)+C1[2, 4]*cosh(beta*x)

C1[2, 1]*sin(alpha*x)+C1[2, 2]*cos(alpha*x)+C1[2, 3]*sinh(beta*x)+C1[2, 4]*cosh(beta*x)

fun1 := Int(y1^4, x = 0 .. 5*(1/100))+Int(y2^4, x = 5*(1/100) .. 1);

Int((C1[1, 1]*sin(alpha*x)+C1[1, 2]*cos(alpha*x)+C1[1, 3]*sinh(beta*x)+C1[1, 4]*cosh(beta*x))^4, x = 0 .. 1/20)+Int((C1[2, 1]*sin(alpha*x)+C1[2, 2]*cos(alpha*x)+C1[2, 3]*sinh(beta*x)+C1[2, 4]*cosh(beta*x))^4, x = 1/20 .. 1)

vals := [alpha = 3.093676148361444, beta = 1.136458914000455*10^2, C1[1, 1] = 1.000000000000000, C1[1, 2] = 0, C1[1, 3] = -0.22069165109e-4, C1[1, 4] = 0, C1[2, 1] = .764799945371359, C1[2, 2] = 0.36674613077895e-1, C1[2, 3] = .95132568684786, C1[2, 4] = -.95132568684786]:

evalf(expand(convert(eval(fun1, vals), exp)));

.13088320034942916574

with(IntegrationTools):

Digits := 100;

100

F2fun1 := Change(Change(op(2, fun1), x = (1*1)*(19*u+1/20), u), u = x, x):

Int((C1[1, 1]*sin(alpha*x)+C1[1, 2]*cos(alpha*x)+C1[1, 3]*sinh(beta*x)+C1[1, 4]*cosh(beta*x))^4+19*(C1[2, 1]*sin((1/20)*alpha*(380*x+1))+C1[2, 2]*cos((1/20)*alpha*(380*x+1))+C1[2, 3]*sinh((1/20)*beta*(380*x+1))+C1[2, 4]*cosh((1/20)*beta*(380*x+1)))^4, x = 0 .. 1/20)

0

new := eval(F2, vals):

map(proc (k) options operator, arrow; k end proc, convert(new, exp)):

.1308832003494291657430777664602299881224552490777598299889111954482828996588502290591220342036629305

``

Download question_ac.mw

You can save some work by having your rm procedure return both the remainder as well as the quotient.

A surrounding procedure can store the quotients in a table (I used the name T), and then -- when finished -- it can construct a list from the entries stored in T.

It would be inefficient to repeatedly augment a list in a loop. So don't do something like the statement in a loop, for list L,
  L := [op(L), func(a, b)];
That's why I stored the quotients in a table, and only at the end turned that into a list.

(Your could also use irem instead of your rm procedure, but I suppose this is a programming exercise. Also see convert(..., base, ...) .)

restart;

rm := proc(a, b) local n; n := 0;
  while 0 <= b - n*a do b - n*a; n := n + 1; end do;
  return n - 1 , b - (n - 1)*a;
end proc:

cv := proc(a::posint, b::posint)
 local T,i,j,r;
 r := b;
 for i while r <> 0 do
   r,T[i] := rm(a,r);
   #T[i] := irem(r,a,'r')
 end do;
 if i = 1 then
   [0]
 else
   [seq(T[j],j = 1 .. i-1)]
 end if;
end proc:

cv(8, 3657);
                          [1, 1, 1, 7]

convert(3657,base,8);
                          [1, 1, 1, 7]

The  LinearAlgebra,General,LinearSolveItr  help page is missing details for the nonsymmetric solver.

But the method can be supplied using the methodoptions optional parameter, similar to how it is documented for the symmetric solver.

(One could examine the code, to figure out additional suboptions that control the methods.)

restart;

with(LinearAlgebra):

infolevel[LinearAlgebra]:=3:

M := Matrix(4,4,[[5.0,0.0,1.0,0.0],[0.2,-1.0],[0.0,3.0,0.0],[-2.0,0.0,0.0,1.0]],
            storage=sparse, datatype=float):

b := Vector(4,1.0,datatype=float):

X := LinearSolve(M,b,method=SparseIterative,methodoptions=[itermethod=CGS]);

LinearSolve: using method SparseIterative

LinearSolve: using method SparseIterative
LinearSolve: calling external function
LinearSolve: using CGS method
LinearSolve: preconditioning with incomplete LU factorization
LinearSolve: level of fill =  0
LinearSolve: using complete pivoting strategy
LinearSolve: dimension of workspaces for preconditioner =  30
LinearSolve: using infinity norm in stopping criteria
LinearSolve: setting maximum iterations to  200
LinearSolve: setting tolerance to  0.10e-7
LinearSolve: NAG hw_f11zaf
LinearSolve: NAG hw_f11daf
LinearSolve: NAG hw_f11dcf
LinearSolve: number of iterations 1
LinearSolve: residual computed last as HFloat(1.1102230246251565e-16)

_rtable[18446884364565750718]

M.X - b;

unknown: hw_SpMatVecMulRR

_rtable[18446884364565751918]

LinearSolve(M,b,method=SparseIterative,methodoptions=[itermethod=RGMRES]);

LinearSolve: using method SparseIterative

LinearSolve: using method SparseIterative
LinearSolve: calling external function
LinearSolve: using RGMRES method
LinearSolve: preconditioning with incomplete LU factorization
LinearSolve: level of fill =  0
LinearSolve: using complete pivoting strategy
LinearSolve: dimension of workspaces for preconditioner =  30
LinearSolve: using infinity norm in stopping criteria
LinearSolve: setting maximum iterations to  200
LinearSolve: setting tolerance to  0.10e-7
LinearSolve: NAG hw_f11zaf
LinearSolve: NAG hw_f11daf
LinearSolve: NAG hw_f11dcf
LinearSolve: number of iterations 2
LinearSolve: residual computed last as HFloat(1.7763568394002505e-15)

_rtable[18446884364565752758]

LinearSolve(M,b,method=SparseIterative,methodoptions=[itermethod=BICGSTAB]);

LinearSolve: using method SparseIterative

LinearSolve: using method SparseIterative
LinearSolve: calling external function
LinearSolve: using Bi-CGSTAB method
LinearSolve: preconditioning with incomplete LU factorization
LinearSolve: level of fill =  0
LinearSolve: using complete pivoting strategy
LinearSolve: dimension of workspaces for preconditioner =  30
LinearSolve: using infinity norm in stopping criteria
LinearSolve: setting maximum iterations to  200
LinearSolve: setting tolerance to  0.10e-7
LinearSolve: NAG hw_f11zaf
LinearSolve: NAG hw_f11daf
LinearSolve: NAG hw_f11dcf
LinearSolve: number of iterations 1
LinearSolve: residual computed last as HFloat(4.440892098500626e-16)

_rtable[18446884364365961446]

 

Download sparseiterative.mw

If I recall, there's no nice, efficient functionality to apply the preliminary work (preconditioning, etc) to multiple RHSs in separate calls. (I could be misremembering -- I didn't check.)

In Maple 2020 you could use printf with the new P format. Or you could use print.

Of course, you could also use sprintf if you prefer a string as return value.

The rules for when if...then...end clauses get indented are not clear to me.

The example below using print does render with more indentation in the Maple GUI than appears when inlined below. And that survives cut&paste, in my Linux.

[edit] One thing that I prefer about the printf format is that it displays semicolon terminators even when optional (eg. before an end). Of course that is a personal preference. I like that it helps prevent a sloppy typo if an extra line is inserted inbetween (or via an $include).

Another thing -- that might matter in some use cases -- is that printf doesn't contain the extra decoration at the start (ie. the printed name and colon-equals) and it's easier to add it than remove it.

restart;

kernelopts(version);

`Maple 2020.0, X86 64 LINUX, Mar 4 2020, Build ID 1455132`

f := proc(x)
   if x <= 2 then
     if x>0 then
       print(-x);
     else
       print(-x^2);
     end if;
   else
     if x>0 then
       print(-x);
     end if;
   end if;
   print(-x);
   x^3;
   if x <= 2 then
     if x>0 then
       if x > -5 then
         print(-x);
       end if;
     else
       print(-x^2);
     end if;
   else
     if x>0 then
       if x > -5 then
         print(-x);
       end if;
     end if;
   end if;
end proc:

 

printf("%P", eval(f));

proc(x)
    if x <= 2 then
        if 0 < x then print(-x); else print(-x^2); end if;
    else
        if 0 < x then print(-x); end if;
    end if;
    print(-x);
    x^3;
    if x <= 2 then
        if 0 < x then
            if -5 < x then print(-x); end if;
        else
            print(-x^2);
        end if;
    else
        if 0 < x then if -5 < x then print(-x); end if; end if;
    end if;
end proc

 

showstat(f);


f := proc(x)
   1   if x <= 2 then
   2       if 0 < x then
   3           print(-x)
           else
   4           print(-x^2)
           end if
       else
   5       if 0 < x then
   6           print(-x)
           end if
       end if;
   7   print(-x);
   8   x^3;
   9   if x <= 2 then
  10       if 0 < x then
  11           if -5 < x then
  12               print(-x)
               end if
           else
  13           print(-x^2)
           end if
       else
  14       if 0 < x then
  15           if -5 < x then
  16               print(-x)
               end if
           end if
       end if
end proc
 

print(f);

proc (x) if x <= 2 then if 0 < x then print(-x) else print(-x^2) end if else if 0 < x then print(-x) end if end if; print(-x); x^3; if x <= 2 then if 0 < x then if -5 < x then print(-x) end if else print(-x^2) end if else if 0 < x then if -5 < x then print(-x) end if end if end if end proc

 

 

Download format_P.mw

The plotting command plots:-surfdata can handle a 2-dimensional Array or Matrix of data (z-values). It has the advantage over matrixplot in the sense that surfdata accepts a 2nd and a 3rd parameter to specify the ranges over which to interpret the independent axes.

If I import your attached .xlsx file then I get a 9-by-4 Matrix of values. I could plot that and specify the ranges for the x- and y-axes, but I don't see how the given data can be expected to give a plot like the one in your Question's image.

You could add additonal options, (such as scaling=constrained , etc), to adjust the look&feel of the plot. See the plot3d,options Help page. Of course the data could also be flipped or transposed.

restart;

#Import("PlotTest.xlsx");

M := ExcelTools:-Import("PlotTest.xlsx");

_rtable[18446884401930645806]

plots:-surfdata(M, 1.25 .. 5.0, 0.4 .. 1.5);

 

Download surfexample.mw

There are several obstacles in the way of using save and read to store and recover a random variable. There are the attributes. There are the modules. In general modules cannot be properly saved to .m format (it takes storing to .mla format to store module locals), but you might be able to kludge around it here. And there is an unknown risk that Statistics might register some information about the previously generated RVs in some additional location which we don't know about.

I think that your ongoing efforts to rip apart Statistic's RVs -- and put them back together again -- is somewhat dubious. It might be workable, but perhaps only partially. It clearly wasn't designed for that. (The package predates objects, and uses its own special, undocumented techniques to get object-oriented effects.)

So I would suggest that instead you store whatever is needed to create the RVs afresh -- using only stock, documented Statistics commands like RandomVariable, Distribution, etc).

Having said that, you might find the following of some interest (Maple 2020.0). I hope that it's clear that the following is in the dubious realm, and not what I meant by using stock, documented techniques.

restart;

V := Statistics:-RandomVariable(Normal(0, 1));
attributes(V);

_R

protected, RandomVariable, _ProbabilityDistribution

Statistics:-Sample(V, 5);

Vector[row](5, {(1) = -1.072424127998269, (2) = -.329077870547065, (3) = -.6170919369097896, (4) = .21446674524529077, (5) = -0.25428128042384635e-1})

K := eval([attributes(V)][3]);

_m139820665320832

save K, "rvs.m";

restart;

with(Statistics): # this is a kludge
read "rvs.m";
unwith(Statistics):

eval(K);

_m139820665280512

V := `tools/genglobal`(_R);
setattribute(V, protected, ':-RandomVariable',
             :-`tools/genglobal`(':-_ProbabilityDistribution')):
attributes(V);
assign([attributes(V)][3], eval(K));

_R

protected, RandomVariable, _ProbabilityDistribution

Statistics:-Sample(V, 5);

Vector[row](5, {(1) = -1.072424127998269, (2) = -.329077870547065, (3) = -.6170919369097896, (4) = .21446674524529077, (5) = -0.25428128042384635e-1})

 

Download RV_save_read.mw

 

There are several ways to go about this.

For example, you could obtain the result directly using the value command (or the active int command).

Or, if it's homework and you've been told to do it in a particular fashion, you could do it step by step. There too you have several choices about how to go about it. I'll give just one way, utilizing integration-by-parts, as illustration. (In this case I don't know what knowledge you have. If you do not see how integration-by-parts is working in each of the three calls below then please say so.)

Or, are you expected to express the formula for integration-by-parts, and then substitute for the various parts, exactly as if you were doing it by hand on paper?

I don't see limits of integration in your Question. Did you intend on supplying them?

restart;

U := Int( (120+2*t)^3/2 * (1+sin(t)), t );

Int((1/2)*(120+2*t)^3*(1+sin(t)), t)

ans2 := simplify( value(U) );

(-4*t^3-720*t^2-43176*t-862560)*cos(t)+(12*t^2+1440*t+43176)*sin(t)+t*(t+120)*(t^2+120*t+7200)

with(Student:-Calculus1):
Understand(Int, sum, constantmultiple):

IntegrationTools:-Parts(U, (120 + 2*t)^3);

((1/2)*t-(1/2)*cos(t))*(120+2*t)^3-(Int(6*((1/2)*t-(1/2)*cos(t))*(120+2*t)^2, t))

IntegrationTools:-Parts(%, (120 + 2*t)^2);

((1/2)*t-(1/2)*cos(t))*(120+2*t)^3-((3/2)*t^2-3*sin(t))*(120+2*t)^2+Int(((3/2)*t^2-3*sin(t))*(480+8*t), t)

IntegrationTools:-Parts(%, 480 + 8*t);

((1/2)*t-(1/2)*cos(t))*(120+2*t)^3-((3/2)*t^2-3*sin(t))*(120+2*t)^2+((1/2)*t^3+3*cos(t))*(480+8*t)-(Int(4*t^3+24*cos(t), t))

IntegrationTools:-Expand(%);

((1/2)*t-(1/2)*cos(t))*(120+2*t)^3-((3/2)*t^2-3*sin(t))*(120+2*t)^2+((1/2)*t^3+3*cos(t))*(480+8*t)-4*(Int(t^3, t))-24*(Int(cos(t), t))

rhs( Rule[power](%) );

((1/2)*t-(1/2)*cos(t))*(120+2*t)^3-((3/2)*t^2-3*sin(t))*(120+2*t)^2+((1/2)*t^3+3*cos(t))*(480+8*t)-t^4-24*(Int(cos(t), t))

rhs( Rule[cos](%) );

((1/2)*t-(1/2)*cos(t))*(120+2*t)^3-((3/2)*t^2-3*sin(t))*(120+2*t)^2+((1/2)*t^3+3*cos(t))*(480+8*t)-t^4-24*sin(t)

ans1 := simplify(%);

(-4*t^3-720*t^2-43176*t-862560)*cos(t)+(12*t^2+1440*t+43176)*sin(t)+t*(t+120)*(t^2+120*t+7200)

simplify(ans2-ans1);

0

 

Download example_byparts.mw

 

See the smartview option on the plot,options Help page

restart; plots:-setoptions(size = [300, 300])

s_eq := diff(s(t), t) = -ir*i(t)*s(t); i_eq := diff(i(t), t) = ir*i(t)*s(t)-rr*i(t); d_eq := diff(d(t), t) = dr*i(t); ics := s(0) = s0, i(0) = i0, d(0) = 0

"i0:=1.E3:    P0:=3.E8:    drate:=0.02:     s0:=0.6*P0:    ir:=(0.1)/(s0):   rr:=1/(30.):  dr:=rr*drate:   "

sol := dsolve({d_eq, i_eq, ics, s_eq}, numeric); tf := 120; plots:-odeplot(sol, [t, d(t)], 0 .. tf)

sol := dsolve({d_eq, i_eq, ics, s_eq}, numeric, output = listprocedure); i := eval(i(t), sol); s := eval(s(t), sol); d := eval(d(t), sol)

tf; plot(d(t), t = 0 .. tf)

120

plot(d(t), t = 0 .. tf, smartview = false)

 

Download plot_view_problem_smartview.mw

Yes, it is a long-standing gripe that the GUI Table (inserted by the GUI when rendering arrays of plots) cannot be programmatically controlled and has suboptimal behavior.

You could try DocumentTools:-Tabulate instead, also making use of some of its additional functionality for controlling placement of the whole Table, dimensions, borders, etc.

I'd be interested in knowing how well its embedded Tables did upon export to PDF.

Here are two ways:

restart

combine(2*s^2*(int(Phi[1, 1](x, T[2])*(diff(Y1(x), x, x)), x = 0 .. x1))+int(Phi[1, 1](x, T[2])*(diff(Y1(x), x, x, x, x)), x = 0 .. x1)-omega_y^2*(int(Y1(x)*Phi[1, 1](x, T[2]), x = 0 .. x1)), int)

int(Phi[1, 1](x, T[2])*(diff(diff(diff(diff(Y1(x), x), x), x), x))+2*s^2*Phi[1, 1](x, T[2])*(diff(diff(Y1(x), x), x))-omega_y^2*Y1(x)*Phi[1, 1](x, T[2]), x = 0 .. x1)

simplify(%);

int(Phi[1, 1](x, T[2])*(diff(diff(diff(diff(Y1(x), x), x), x), x)+2*s^2*(diff(diff(Y1(x), x), x))-omega_y^2*Y1(x)), x = 0 .. x1)

IntegrationTools:-Combine(2*s^2*(int(Phi[1, 1](x, T[2])*(diff(Y1(x), x, x)), x = 0 .. x1))+int(Phi[1, 1](x, T[2])*(diff(Y1(x), x, x, x, x)), x = 0 .. x1)-omega_y^2*(int(Y1(x)*Phi[1, 1](x, T[2]), x = 0 .. x1)), int)

int(Phi[1, 1](x, T[2])*(diff(diff(diff(diff(Y1(x), x), x), x), x)+2*s^2*(diff(diff(Y1(x), x), x))-omega_y^2*Y1(x)), x = 0 .. x1)

NULL

Download example_int_ac.mw

You could compile Jave code by doing an escaped shell command, (see ssystem). Depending on what is in it, you could run it with an external call (see define_external).

First 7 8 9 10 11 12 13 Last Page 9 of 218