acer

32567 Reputation

29 Badges

20 years, 28 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The angle-bracket shortcut syntax for Matrix construction supports this functionality. For example,

a := Matrix(2,3,symbol=A);

a := Matrix(2, 3, {(1, 1) = A[1, 1], (1, 2) = A[1, 2], (1, 3) = A[1, 3], (2, 1) = A[2, 1], (2, 2) = A[2, 2], (2, 3) = A[2, 3]})

b := Matrix(3,3,symbol=B);

b := Matrix(3, 3, {(1, 1) = B[1, 1], (1, 2) = B[1, 2], (1, 3) = B[1, 3], (2, 1) = B[2, 1], (2, 2) = B[2, 2], (2, 3) = B[2, 3], (3, 1) = B[3, 1], (3, 2) = B[3, 2], (3, 3) = B[3, 3]})

c := Matrix(2,2,symbol=C);

c := Matrix(2, 2, {(1, 1) = C[1, 1], (1, 2) = C[1, 2], (2, 1) = C[2, 1], (2, 2) = C[2, 2]})

<a|c>;

Matrix([[A[1, 1], A[1, 2], A[1, 3], C[1, 1], C[1, 2]], [A[2, 1], A[2, 2], A[2, 3], C[2, 1], C[2, 2]]])

<a,b>;

Matrix([[A[1, 1], A[1, 2], A[1, 3]], [A[2, 1], A[2, 2], A[2, 3]], [B[1, 1], B[1, 2], B[1, 3]], [B[2, 1], B[2, 2], B[2, 3]], [B[3, 1], B[3, 2], B[3, 3]]])

Download Matrix_stack_augment.mw

That syntax is so simple that having dedicated commands for it would be overkill.

You may also use this to stack/augment a Matrix by a Vector (of the appropriate orientation).

You can suppress the visual display of results by using a fill colon (instead of semicolon) as the statement terminator.

For sorting there are various kinds of example. You should explain the specific goals, explicitly.

You can pass the extra option  output=string  to the CodeGeneration:-Matlab command.

Eg,
   CodeGeneration:-Matlab(func, output=string);

Then you can write that string to a file, using fprintf, or FileTools:-Text:-WriteString, etc.

It sounds like you are looking for a 2D parametric plot.

For example (using made up values for the other parameters),

plot([eval([x(t),y(t)],[A=0.9,v=2,m=1,n=1,alpha=1,beta=1])[], t=0.3..1.5],
        labels=["x","y"]);

With the code you supplied, the following both work:

  ribbonplot5([cos, sin, cos + sin], -Pi .. Pi,numpoints=20);
  ribbonplot5([cos(x), sin(x), cos(x) + sin(x)],x=-Pi .. Pi,numpoints=20);

Consider this simpler plotting example, and these two different kinds of calling sequence,

  plot(sin, 0..Pi);
  plot(sin(x), x=0..Pi);

The first uses a so-called operator-form calling calling sequence syntax, and the second uses a so-called expression-form calling sequence. (Also see the calling sequences shown on this Help page.)

The first passes an operator (procedure), which the second passes an expression with an unknown (here, the name x).

It does not make good sense to mix and match those two distinct kinds of usage. It does not make good sense to pass an operator (procedure) as the first argument and a name in the second argument. That would be muddled up and poor programming.

That ribbonplot5 procedure simply doesn't do as good a job as plot at checking for such a mismatch and producing a helpful error message. Eg,

  plot([sin, cos], x=0..Pi);
Error, (in plot) expected a range but received x = 0 .. Pi

note: This kind of distinction between expression-form and operator-form calling sequence is present elsewhere, eg. for fsolve, evalf(Int(...)), Optimization:-Minimize, etc.

You might use the orientation 3D plotting option.

For example,

restart:

with(plots): with(plottools):

d := 1.25:
a := 1:

chl := [[a/2, a/2, a/2],
          [a/2, -a/2, -a/2],
          [-a/2, a/2, -a/2],
          [-a/2, -a/2, a/2]]:
f := [[[-d/2, -d/2, -d/2], [-d/2, d/2, -d/2], [d/2, d/2, -d/2], [d/2, -d/2, -d/2], [-d/2, -d/2, -d/2]],
      [[-d/2, -d/2, d/2], [-d/2, d/2, d/2], [d/2, d/2, d/2], [d/2, -d/2, d/2], [-d/2, -d/2, d/2]],
      [[-d/2, d/2, d/2], [-d/2, d/2, -d/2], [d/2, d/2, -d/2], [d/2, d/2, d/2], [-d/2, d/2, d/2]],
      [[-d/2, -d/2, d/2], [-d/2, -d/2, -d/2], [d/2, -d/2, -d/2], [d/2, -d/2, d/2], [-d/2, -d/2, d/2]]]:
l := seq(seq(line(op(i-1,j),
              op(i, j),
                        colour = black,
                 style = surface),
            i= 2..5), j in f):    
t := seq(line([0,0,0],
            i,
            colour = black,
            thickness = 30,
            style = surface),
            i in chl):
hydr := seq(sphere(3*i/4,
                   a/4,
                   colour = gray,
                   style = surface),
                   i in chl):
char := sphere([0,0,0],
               a/3,
               colour=black,
               style = surface):

display(l, t, hydr, char, axes = none, orientation=[45,90,0]);

display(l, t, hydr, char, axes = none, orientation=[45,54,0]);

display(l, t, hydr, char, axes = none, orientation=[135,90,0]);

Download tareaclase6_ac.mw

An imported image (as float[8] Array) can be used for the coloring in a density-plot structure.

Once appropriately scaled, this can be translated to arbitrary x-y positions.

The following code could be made more efficient (and easy, with a re-usable procedure to scale/translate/etc). But I'd like to know whether it will suffice, before making the effort.

Naturally one can change the Read line below, to instead use some other external image file. (The OP didn't provide an image file.) All the code below needs is the usefully scaled (70x70x3 works ok) Array assigned to img.

restart;

with(plottools, transform): with(ImageTools):

img := Scale(Read(cat(currentdir(),"/smdrone.jpg")),1..75)[1..70]:

R := Rotate(img,':-right'):

nc, nr := LinearAlgebra:-Dimensions(R[..,..,1]);

70, 70

Q:=PLOT(GRID(-0.15..0.15,-0.15..0.15,
             Matrix(nc,nr,'datatype'=':-float[8]'),
             COLOR(RGB,R)),STYLE(PATCHNOGRID)):

plots:-display(
  transform((x,y)->[x+Pi/2,y+1.1])(Q),
  transform((x,y)->[x+Pi/5,y+0.7])(Q),
  transform((x,y)->[x+5*Pi/6,y+0.7])(Q),
  transform((x,y)->[x+Pi+0.2,y+0.1])(Q),
  transform((x,y)->[x-0.2,y+0.1])(Q),

  plot(sin(x),x=0..Pi),

  scaling=constrained, view=[-0.4..Pi+0.4,0..1.5],
  axis[1]=[tickmarks=[seq(i*Pi/4=i*Pi/4,i=0..4)]],
  size=[500,350]);

Download image_plot.mw

I suspect that the GUI will be generally less sluggish using such density-plots than it would with, say, colored point-plot assemblies.

That density-plot structure could actually be formed via the plots:-densityplot command, using the Array from the image. I simply found it easier to form it directly, as above.

The Fractals:-EscapeTime commands produce images (in the float[8] rtable sense), not plots.

You can "animate" a discrete number of images (or even calls to the Mandelbrot command at modest size, it's that fast) using Explore.

But you cannot nicely export that animated rendering to an external file. Maple's directly export functionality is limited to exporting a sequence of actual plots. Converting those images (rtables) into, say, densityplots would produce results too large and unwieldy for the GUI and its export drivers to handle well (if at all).

What you could do, instead, is export the images (rtables) directly to separate external image files (.gif, .png, what have you), using the ImageTools:-Write command. And then use an external 3rd party tool on your OS to assemble a movie format file (mpeg2, mp4, .gif, etc) from those.

Here are two alternatives to plots:-display, one using DocumentTools:-Tabulate and the other using DocumentTools primitives.

If you really want you could use more Table nesting (and suppressed borders) to get precisely the layout you showed. Perhaps more effort than it's worth...

(Sorry, I don't think that this forum will properly inline this worksheet here.)

question5_ac.mw

I don't why you wouldn't expect a(i)=0 and c(i)=0 to follow from your given a(0)=0 and c(0)=0. Perhaps you (or I) have made a mistake?

For fun, procedures Ap and Cp below take a0,c0 initial values as 2nd and 3rd arguments respectively.

The procedures Ap and Cp are programmatically generated from the recurrence equations. (I didn't feel like wrestling with rsolve.) So you can regenerate them for some modest edits of the equations.

In the example I use a0=0.1 and c0=0.1.

restart

eqns := {a(i) = (1+10^(-5)*(0.1e-1*(i-1)-0.7e-2)/(0.1e-3))*a(i-1)+.1*10^(-5)*c(i-1), c(i) = 0.1e-1*10^(-5)*(i-1)*a(i-1)/(0.1e-3)+((1-10^(-5))*.1)*c(i-1)}

{a(i) = (.9983000000+0.1000000000e-2*i)*a(i-1)+0.1000000000e-5*c(i-1), c(i) = 0.1000000000e-2*(i-1)*a(i-1)+0.9999900000e-1*c(i-1)}

Ap := subs(_d = subs([a = Ap, c = Cp], subsindets(eval(a(i), eqns), specfunc({a, c}), proc (u) options operator, arrow; (op(0, u))(op(u), a0, c0) end proc)), proc (i, a0, c0) option remember; if not i::nonnegint then return ('procname')(i, a0, c0) elif i = 0 then a0 else _d end if end proc)

proc (i, a0, c0) option remember; if not i::nonnegint then return ('procname')(i, a0, c0) elif i = 0 then a0 else (.9983000000+0.1000000000e-2*i)*Ap(i-1, a0, c0)+0.1000000000e-5*Cp(i-1, a0, c0) end if end proc

Cp := subs(_d = subs([a = Ap, c = Cp], subsindets(eval(c(i), eqns), specfunc({a, c}), proc (u) options operator, arrow; (op(0, u))(op(u), a0, c0) end proc)), proc (i, a0, c0) option remember; if not i::nonnegint then return ('procname')(i, a0, c0) elif i = 0 then c0 else _d end if end proc)

proc (i, a0, c0) option remember; if not i::nonnegint then return ('procname')(i, a0, c0) elif i = 0 then c0 else 0.1000000000e-2*(i-1)*Ap(i-1, a0, c0)+0.9999900000e-1*Cp(i-1, a0, c0) end if end proc

``

plots:-display(plots:-listplot([seq(Ap(i, .1, .1), i = 1 .. 50)], color = red, style = point), plots:-listplot([seq(Cp(i, .1, .1), i = 1 .. 50)], color = blue, style = point))

``

Download rsolve_for_system_of_recursive_equations_acc.mw

There are various ways to programmatically make the result appear in terms of J/mol as units. See attachment below for three of them.

It numerically better to round final results to 3 digits instead of calling evalf(...,3) or evalf[3](...) which do computations at lower precision and can incur unnecessarily greater roundoff error than usual.

I am deliberately avoiding using right-click units-formatting or numeric (float) formatting via the GUI.

(For some reason this forum is not letting me inline my revised Document, sorry).
Download question4_ac.mw

In terms of programmatically determining significant digits you might try either the Tolerances or the ScientificErrorAnalysis packages, depending on your concept of error in the supplied input float values.

You wrote that you knew how to construct the filled 2D plot. Great.

You can transform a 2D plot to 3D, for some terse code for your goal.

I shift (before and after, to positive y) to allow the filled portion to survive the transformation more nicely.

restart;

with(plottools):

#Circle of reference
R0 := 1:
C0 := t -> < cos(t), sin(t) >:

#Variable radius
R := t -> R0*(1 + 1/2*sin(t)):

#Variable phase
Dt := t -> Pi/2*sin(2*t):
  
#CONCAVE Curve
C := t-> R(t)*C0(t - Dt(t)):

P2D := plot([seq(C(t)+<0,1>),t=0..2*Pi],
            filled=true,color=red,transparency=0 ):

transform((x,y) -> [x,y-1,0])(P2D);

Download 2Dfill_transf_3D.mw

You asked about doing the loop without the list from 1 to 5 for the index. Here below is another common loop syntax choice.

The rest is also done more simply, without duplicated input of those multiples of Pi, etc.

lev := [ 2*k*Pi*I, (2*k+1)*Pi*I, Pi*I/2, 3*Pi*I/2, Pi*I/3 ]:

for i from 1 to 5 do
  'exp'(lev[i]) = exp(lev[i]) assuming k::integer;
end do;

exp((2*I)*k*Pi) = 1

exp(I*(2*k+1)*Pi) = -1

exp(((1/2)*I)*Pi) = I

exp(((3/2)*I)*Pi) = -I

exp(((1/3)*I)*Pi) = 1/2+((1/2)*I)*3^(1/2)

Download exp_seq.mw

Your examples (so far) don't require evalc or convert(...,radical).

If you want it terser you could also begin that loop as,
     for i to 5 do
which would start by default from 1.

The problem is that you've made several mistakes. It's not a configuration issue.

Your list li is created with roll, but it ought to be calls like roll() .

You call solve on f(x), but the procedure you created was assigned to g, not f.

If you want floating-point results then you can use fsolve here, rather than solve.

restart;

g := x -> (x^5)/5 - x*x:

roll := rand(100):

li := [seq(roll(), i=1..5)];

[92, 44, 95, 5, 97]

for y in li do
  x = fsolve(g(x) - y);
end do;

x = 3.494433398

x = 3.056377195

x = 3.515282609

x = 2.174769278

x = 3.528902472

Download rand_usage.mw

You may use expand for Q2.

Both Q1 and Q2 require fixing the problem of the erroneous multiplication syntax.

restart;

eq14_1_3 := w[NET] = Delta*T[Sfg];

w[NET] = Delta*T[Sfg]

eq14_2 := w[NET] = -((v[2] + v[3])/2)*((-DeltaP + P) - P) - ((v[1] + v[4])/2)*((P - P) + DeltaP);

w[NET] = (1/2)*(v[2]+v[3])*DeltaP-(1/2)*(v[1]+v[4])*DeltaP

simplify(eq14_2);

w[NET] = -(1/2)*DeltaP*(-v[2]-v[3]+v[1]+v[4])

collect(eq14_2, DeltaP);

w[NET] = DeltaP*((1/2)*v[2]+(1/2)*v[3]-(1/2)*v[1]-(1/2)*v[4])

eq14_2_2 := rhs(eq14_1_3) = rhs(eq14_2);

Delta*T[Sfg] = (1/2)*(v[2]+v[3])*DeltaP-(1/2)*(v[1]+v[4])*DeltaP

expand(eq14_2_2 / DeltaP);

Delta*T[Sfg]/DeltaP = (1/2)*v[2]+(1/2)*v[3]-(1/2)*v[1]-(1/2)*v[4]

expand(eq14_2 / DeltaP);

w[NET]/DeltaP = (1/2)*v[2]+(1/2)*v[3]-(1/2)*v[1]-(1/2)*v[4]

Download Q20220110_ac.mw

You need to apply Re (or Im) to the call y(x) in the view(s), rather than to sol.

restart;

odesys := {diff(y(x),x) + I*y(x) = 0, y(0) = 1}:
sol := dsolve(odesys, numeric, range=0..1):

plots:-odeplot(sol, [x,Re(y(x))], x=0..1);
plots:-odeplot(sol, [x,Im(y(x))], x=0..1);

plots:-odeplot(sol, [-Im(y(x)),Re(y(x))], x=0..1);

# Or, if you don't want to use odeplot,
plot(t->Re(eval(y(x), sol(t))), 0..1);
plot(t->Im(eval(y(x), sol(t))), 0..1);

etc.

First 77 78 79 80 81 82 83 Last Page 79 of 338