acer

32313 Reputation

29 Badges

19 years, 312 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

From some of your other recent Questions it seems that you are interested in module programming for involved purposes, eg. your large automated integration and differential equations solving and testing. In other words, likely some serious, involved, and lengthy code.

I suggest shooting for code maintainability over convenience.

I also think that qualified module references are much superior to so-called short-form names, in lengthy production-quality code. For example, I strongly prefer B:-foo() over just foo() following uses or use or with. I think that it's important that the code be managable, and is legible, understandable and naturally unambiguous. I think that is a far better way to manage the name-space.

If you really prefer terser code, for reading, then the qualified module references can be made shorter. Control of that can be done without having to utilize the uses functionality.

I also think that large amounts of valued code for procedures and modules should be kept in plaintext files -- for safety and robustness of the format, as well as for the ability to do good revision control.

Having said all that, I suggest a plaintext file format (which can be accessed in the GUI using the read command), that might look something like the following. Here the actual names of the modules and submodules can be easily changed later on, because they are defined in a centralized manner.

This is just an example,

$define AM=Amodule
$define BSM=Bsubmodule
$define CSM=Csubmodule

AM:=module()
   export BSM:=module()
     export foo:=proc()
         print("In foo()");
     end proc;
   end module;

   export CSM:=module()
      export boo:=proc()
           BSM:-foo();
      end proc;
   end module;
end module:

$undef CSM
$undef BSM
$undef AM

How about,

    `.`( seq(A[i], i=1..n) );

Naturally, n would be some actual integer.

 

Did you first embed a Speaker Component, say from the Embedded Components palette?

Did you check that the identity property of the Speaker Component matched the second argument passed to the Play command?

Do the other right-click properties of the embedded Speaker Component look reasonable? (eg. not muted, volume>0, driver device looks right, etc)

 

restart:

kernelopts(version);

`Maple 2018.2, X86 64 LINUX, Nov 16 2018, Build ID 1362973`

T := 10^(-6): delta := 10: m := 1:
alpha:= 75/10: v := 65: mu := 8:

z := sqrt((omega^2 - 4*m^2)/alpha^2 - v^2/alpha^2*(4 *delta/alpha*tan(theta)^2
           - v^4/alpha^4*tan(theta)^4)):

a := sec(theta)/sqrt(2)*sqrt((2 *delta)/alpha - v^2/alpha^2*tan(theta)^2 + z):

f1 := 1/(exp(( omega/2 - mu)/T) + 1):
f2 := 1/(exp((- (omega/2) - mu)/T) + 1):

A1 := (-(f1 - f2)*abs(omega/(4*a*alpha*cos(theta)^2
                      *(-delta+ a^2 *alpha* cos(theta)^2)
                      + 2*a*v^2*sin(theta)^2 + 1/10000))):

b := sec(theta)/sqrt(2)*sqrt((2*delta)/alpha - v^2/alpha^2*tan(theta)^2 - z):

f3 := 1/(exp(( omega/2 - mu)/T) + 1):
f4 := 1/(exp((- (omega/2) - mu)/T) + 1):

A2 := (-(f3 - f2)*abs(omega/(4*b*alpha*cos(theta)^2
                      *(-delta+ b^2 *alpha* cos(theta)^2)
                      + 2*b*v^2*sin(theta)^2 + 1/10000))):

Digits:=15:
CodeTools:-Usage(plot(Omega->Int(subs(omega=Omega,unapply(A1+A2,theta)),
                                 0..2*Pi,method=_d01ajc,epsilon=1e-4),
                      0..50));

memory used=7.80MiB, alloc change=0 bytes, cpu time=989.00ms, real time=990.00ms, gc time=0ns

 

Download code_Int_ac.mw

That kind of labeling is available in the Command Line Interface (aka CLI or TTY), and in the Classic GUI.

It is not enabled with default settings in the Java GUI. But it can be enabled by adjusting various interface settings.

Unfortunately the line-breaking doesn't work properly in the Java GUI, for such labeling. Which is a shame because (when working properly) it is a very nice feature. It can make a long expression legible and comprehensible, that would otherwise take many pages to pretty-print.

restart;

kernelopts(version);

`Maple 2018.2, X86 64 LINUX, Nov 16 2018, Build ID 1362973`

sol:=[solve](x^3+x^2-1,x,Explicit):

 

interface(labeling=true):         # default is true
interface(typesetting=extended):  # default is extended
interface(prettyprint=3):         # default for GUI is 3

sol;

[(1/6)*(100+12*69^(1/2))^(1/3)+(2/3)/(100+12*69^(1/2))^(1/3)-1/3, -(1/12)*(100+12*69^(1/2))^(1/3)-(1/3)/(100+12*69^(1/2))^(1/3)-1/3+((1/2)*I)*3^(1/2)*((1/6)*(100+12*69^(1/2))^(1/3)-(2/3)/(100+12*69^(1/2))^(1/3)), -(1/12)*(100+12*69^(1/2))^(1/3)-(1/3)/(100+12*69^(1/2))^(1/3)-1/3-((1/2)*I)*3^(1/2)*((1/6)*(100+12*69^(1/2))^(1/3)-(2/3)/(100+12*69^(1/2))^(1/3))]

interface(labeling=true):         # default is true
interface(labelwidth=20):         # default is 20
interface(typesetting=standard):  # default is extended
interface(prettyprint=2):         # default for GUI is 3

sol;

"([[`%1`=1/6 (100+12 sqrt(69))^(1/3)-(2)/(3 (100+12 sqrt(69))^(1/3))]])"

interface(labeling=true):         # default is true
interface(labelwidth=15):         # default is 20
interface(typesetting=standard):  # default is extended
interface(prettyprint=2):         # default for GUI is 3

sol;

"([[`%1`=1/6 (100+12 sqrt(69))^(1/3)],[`%2`=(2)/(3 (100+12 sqrt(69))^(1/3))],[`%3`=1/12 (100+12 sqrt(69))^(1/3)],[`%4`=(1)/(3 (100+12 sqrt(69))^(1/3))]])"

interface(labeling=true):         # default is true
interface(labelwidth=10):         # default is 20
interface(typesetting=standard):  # default is extended
interface(prettyprint=2):         # default for GUI is 3

sol;

"([[`%1`=(100+12 sqrt(69))^(1/3)],[`%2`=1/6 `%1`-(2)/(3 `%1`)]])"

 

Download expr_labeling.mw

In some situations the LargeExpression package has some related utility.

And there are also the GUI Equation Labels, which have a different utility.

It's not clear what range for x you wish to allow, or what upper bound for k you wish to consider, or whether you want the plot to illustrate k values.

Here are some ideas. You can solve synbolically for x that make k positive (or not).

restart;

gamma__1:=2;

2

k:=gamma__1*(100-x)/100-x*0.05*gamma__1*(100-x)/100;

2-(1/50)*x-0.1000000000e-2*x*(100-x)

alpha:=0.01+0.00001*((k+2*gamma__1)/2)^2;

0.1e-1+0.1e-4*(3-(1/100)*x-0.5000000000e-3*x*(100-x))^2

M:=41539.42878*alpha;

415.3942878+.4153942878*(3-(1/100)*x-0.5000000000e-3*x*(100-x))^2

unwanted:=solve(k<0,{x});

{20. < x, x < 100.}

plot(M,x=0..20,color=red);

plots:-dualaxisplot(M,k, x=0..20, color=[red,blue],
                    axis[2]=[[color=red],[color=blue]]);

plot(piecewise(And(op(unwanted)),undefined,M),x=0..150,color=red);

plots:-dualaxisplot(piecewise(And(op(unwanted)),undefined,M),
                    piecewise(And(op(unwanted)),undefined,k),
                    x=0..150, color=[red,blue],
                    axis[2]=[[color=red],[color=blue]]);

 

Download pw.mw

There appears to be a corrupted Plot XML element (I think in section Opg 3 of Rumintegraler Uge 6).

With that bad element removed, the remaining contents are available, see attachment. This recovers twelve Sections, up to Uge 12. (The Maple 2021.0 GUI could, sadly, only recover the first five of those.)

matOpgaver_1_ac.zip

I strongly suggest that you keep your own regular backups of lengthy and precious assignments done as Maple worksheets.

[edit] I will add this to my collection of earlier reports of corrupted worksheets of Danish students. I'll have to repeat my earlier notes that the manner in which the GUI "repairs" corrupted XML elements could be significantly improved..

@tarik_mohamadi The expression Bi-1 divides both the real and the imaginary components of the determinant expression (eq), under the assumption that remaining parameters are real.

I could get the following (avoiding source=csv, as an option),

restart;

kernelopts(version);

`Maple 2021.0, X86 64 LINUX, Mar 5 2021, Build ID 1523359`

ImportMatrix("t.txt", source=delimited, delimiter=",");

Matrix(3, 4, {(1, 1) = 1, (1, 2) = 2, (1, 3) = "0", (1, 4) = 4, (2, 1) = 1, (2, 2) = 2, (2, 3) = "1", (2, 4) = 4, (3, 1) = 1, (3, 2) = 2, (3, 3) = "A", (3, 4) = 4})

lprint(%);

Matrix(3,4,{(1, 1) = 1, (1, 2) = 2, (1, 3) = "0", (1, 4) = 4, (2, 1) = 1, (2, 2
) = 2, (2, 3) = "1", (2, 4) = 4, (3, 1) = 1, (3, 2) = 2, (3, 3) = "A", (3, 4) =
4},datatype = anything,storage = rectangular,order = Fortran_order,attributes =
[_fill = ""],shape = [])

Download nm_ImportMatrix.mw

I suggest:

 -- The Programming Guide

 -- Understanding Maple, by Ian Thompson

The first comes bundled with Maple, in its Help system.  The second is relatively up-to-date (2016), well written, brief yet to the point, mostly of good sensible quality, and inexpensive.

If you are going to program in Maple then I suggest you start off by toggling your GUI default modes to:
  -- Worksheet, instead of Document
  -- 1-D plaintext input "Maple Notation", instead of typeset "2-D Math"
(See Tools->Options->Display and Tools:-Options->Interface, respectively.)

How about StringTools:-SubstituteAll, replacing with the empty string?

s:=" \\left \\int x \\,dx \\left":

StringTools:-SubstituteAll(s,"\\left","");

          "  \int x \,dx "

I don't know whether you care about residual white-space,

with(StringTools):
SubstituteAll(SubstituteAll(SubstituteAll(s," \\left ",""),
                            "\\left ",""),
              " \\left","");

          "\int x \,dx"

After issuing stopat(proc1), you need to actually run an example that calls that proc1 procedure. Then the debugger will appear, when the computation invokes that procedure.

I don't think that you should compute the plot as you describe with a fixed z-step-size, eg. by passing the adaptive=false and say numpoints=floor((9-2)/0.5)+1 options to the plot command (modifying how Tom called it). The result would be very coarse.

Tom's suggestion utilizes the default adaptive plotting of the plot command, sampling Z over the range -5..5 according to where it ascertains that more points would help. (This is true whether the z-range is 2..9 or -5..5.)

The computing time for Tom's adaptive plot call can be roughly halved by memoization (eg. storing the fsolve results rather than calling it twice, once for each of x and y).

But if you're willing to experiment with (or compute) the x- and y-ranges then for the example Tom invented even smoother curves can be obtained, and much quicker, eg. through the implicitplot command.

There are also regions in which the plots from the two methods visibly differ (eg. where the curves become steep/multivalued). I leave it to you to judge.

restart;

plots:-setoptions(size=[400,400]):

eqns:=[2*x+3*cos(y)+z^2=0, sin(x)+y+2*z=1];

[2*x+3*cos(y)+z^2 = 0, sin(x)+y+2*z = 1]

str:=time[real]():
T:=eliminate(eqns, [z]);
P:=plots:-implicitplot(T[2], x=-12..12, y=-12..12):
xydat:=plottools:-getdata(P)[-1]:
zdat:=<[seq(eval(eval(z,T[1]),[x=xydat[i,1],y=xydat[i,2]]),
            i=1..op([1,1],xydat))]>:
plot( [<zdat|xydat[..,1]>, <zdat|xydat[..,2]>],
      thickness=2, labels=[z, ""] );
(time[real]()-str)*'seconds';

[{z = -(1/2)*sin(x)-(1/2)*y+1/2}, {sin(x)^2+2*sin(x)*y+y^2+12*cos(y)-2*sin(x)+8*x-2*y+1}]

.100*seconds

func:=proc(Z) option remember;
        if not Z::numeric then return 'procname'(args); end if;
        fsolve(eval(eqns, z=Z));
      end proc:

forget(func):
str:=time[real]():
plot( [ 'eval'(x,func(Z)), 'eval'(y,func(Z)) ], Z=-5...5,
      thickness=2, labels=[z, ""] );
(time[real]()-str)*'seconds';

7.135*seconds

forget(func):
str:=time[real]():
plot( [ 'eval'(x,func(Z)), 'eval'(y,func(Z)) ], Z=2...9,
      thickness=2, labels=[z, ""] );
(time[real]()-str)*'seconds';

9.901*seconds

str:=time[real]():
a := minimize( solve(T[1][1],y), x=-40..40, z=2..9):
b := maximize( solve(T[1][1],y), x=-40..40, z=2..9):
T:=eliminate(eqns, [z]);
P:=plots:-implicitplot(T[2], x=-40..40, y=a..b):
xydat:=plottools:-getdata(P)[-1]:
zdat:=<[seq(eval(eval(z,T[1]),[x=xydat[i,1],y=xydat[i,2]]),
            i=1..op([1,1],xydat))]>:
plot( [<zdat|xydat[..,1]>, <zdat|xydat[..,2]>],
      thickness=2, labels=[z, ""] );
(time[real]()-str)*'seconds';

[{z = -(1/2)*sin(x)-(1/2)*y+1/2}, {sin(x)^2+2*sin(x)*y+y^2+12*cos(y)-2*sin(x)+8*x-2*y+1}]

.180*seconds

 

Download impl_fun.mw

Is there a special reason why you haven't provided us with your full example, so that we could test out ideas?

Editing your original.

In the Maple GUI the results from the loop are actually shown for all three of i=1..3 . It's a quirk of this forum that they don't each render when inlined here.

You don't have to use a loop, of course. But I prefer indexed L[i] to concatenated L||i .

restart

lxi := [1, 3, 0]

[1, 3, 0]

Lu := [2, 2, 1]

[2, 2, 1]

Lg := proc (n, i) local j; simplify(mul(`if`(i <> j, (xi-lxi[j])/(lxi[i]-lxi[j]), 1), j = 1 .. n), size) end proc

for i to 3 do L[i] := Lg(3, i) end do; i := 'i'

(-xi+1)*(-(1/3)*xi+1)

NULL

U := sum(Lu[i]*L[i], i = 1 .. 3)

-(xi-3)*xi+(1/3)*(xi-1)*xi+(-xi+1)*(-(1/3)*xi+1)

"(=)"

-(1/3)*xi^2+(4/3)*xi+1

``

Download Lagrange_interpolation_ac.mw

Perhaps more graceful would be a revision to procedure Lg, such that it accepted lxi as an argument, and deduced n=numelems(lxi).
 

(This seems a tiny bit tidier than your followup A_little_example_ac.mw )

You can get more arrows while still using the VectorField command from the Student:-VectorCalculus package (as you've done in your attachment).

You can do that by supplying the fieldoptions option to the VectorField command, using the grid suboption in the list in the right-hand-side.

Adjusting your example,

restart

with(Student:-VectorCalculus)

l := int(1/((sqrt(x^2+1^2)+1)*sqrt(x^2+1^2)), x)

a := int(x/((sqrt(x^2+y^2)+1)*sqrt(x^2+y^2)), x)

b := int(y/((sqrt(x^2+y^2)+1)*sqrt(x^2+y^2)), x)

v1 := VectorField(`<,>`(a, b))

VectorField(`<,>`(a, b), output = plot, fieldoptions = [grid = [13, 13]], scaling = constrained, view = [-100 .. 100, -100 .. 100])

 

Download How_to_add_more_arrows_acc.mw

You can read about this in the Help page for the VectorField command. When you encounter a difficulty with some command then a good place to look is its Help page (also available within the Maple GUI itself).

First 88 89 90 91 92 93 94 Last Page 90 of 336