acer

29759 Reputation

29 Badges

19 years, 319 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

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.

Here's another simple implementation, generating new unassigned constants for each call (and not adding such if it returns an unevaluated int call).

restart;

 

Cint:=proc(ee,t::name)
  global _C:=_C0; local res;
  res:=int(ee,t);
  if not res::specfunc(anything,int) then
    res+`tools/genglobal`('_C');
  else res; end if;
end proc:

 

Cint(x,x);

(1/2)*x^2+_C0

Cint(u*sin(u),u);

sin(u)-u*cos(u)+_C1

Cint(s*exp(s),s);

(s-1)*exp(s)+_C2

Cint(exp(sin(x)),x);

int(exp(sin(x)), x)

Cint(Cint(sin(x+y),y),x);

_C3*x-sin(x+y)+_C4

Download intconst.mw

Naturally you could also add that procedure to a custom package (module, loadable using with). Then you could name it int and call it that way.

restart;

 

Cint:=module() export int; option package;
  int:=proc(ee,t::name)
  global _C:=_C0; local res;
  res:=:-int(ee,t);
  if not res::specfunc(anything,:-int) then
    res+`tools/genglobal`('_C');
  else res; end if;
end proc:
end module:

 

with(Cint);

[int]

 

int(x,x);

(1/2)*x^2+_C0

int(u*sin(u),u);

sin(u)-u*cos(u)+_C1

int(s*exp(s),s);

(s-1)*exp(s)+_C2

int(exp(sin(x)),x);

int(exp(sin(x)), x)

int(int(sin(x+y),y),x);

_C3*x-sin(x+y)+_C4

Download intconstpkg.mw

I don't think that you should try to change the behaviour of :-int itself (via unprotect) lest some things break internally.

I find the goal here to be slightly suspicious. Having said that,

restart:

alias(f=f(t)):
alias(g=g(t)):

diff([f, g], t);

[diff(f, t), diff(g, t)]

a := parse(convert([alias()],string));

[f, g]

diff(a,t);

[diff(f, t), diff(g, t)]

Download alias_oof.mw

Others have addressed your direct query about the persistence of 0.0*I.

You might also be interested to know that the plot command can ignore zero (or very small) floating-point imaginary artefacts, in order to produce the desired result.

I suppose that you are examining the effects of transforming your earlier integral, and in particular the result of some change of variables (possibly on an indefinite integral, then using FTOC) where the end result is better behaved numerically. Ie,

One possibility is to convert the form, manually.

expr2 := 2*EllipticF(sqrt(sin(`&phi;__0`))/sqrt(sin(`&phi;__0`)+1), I*sqrt(-sin(`&phi;__0`)^2+1)/(sin(`&phi;__0`)-1))/sqrt(1-sin(`&phi;__0`))

2*EllipticF(sin(phi__0)^(1/2)/(sin(phi__0)+1)^(1/2), I*(-sin(phi__0)^2+1)^(1/2)/(sin(phi__0)-1))/(1-sin(phi__0))^(1/2)

eval(expr2, `&phi;__0` = .1)

.6336176952+0.*I

simplify(frontend(convert, [expr2, Int], [{`*`, `+`, specfunc(EllipticF)}, {}])); newexpr2 := `assuming`([simplify(combine(value(%)))], [`&phi;__0` > 0, `&phi;__0` < Pi])

(EllipticK((1/2)*(2*sin(phi__0)+2)^(1/2))-EllipticF(1/(sin(phi__0)+1)^(1/2), (1/2)*2^(1/2)*(sin(phi__0)+1)^(1/2)))*2^(1/2)

eval(newexpr2, `&phi;__0` = .1); evalf(%)

.6336176979

NULL

Download _zero_times_imaginery_unit_ac.mw

Another possibility is to utilize key assumptions under a change of variables,

H := Int(1/sqrt(sin(x0)-sin(x)),x=0..x0);

Int(1/(sin(x0)-sin(x))^(1/2), x = 0 .. x0)

raw := simplify(value(IntegrationTools:-Change(H,s=sin(x),s))) assuming s>0, s<1, x0>0, x0<Pi/2;

(-EllipticF(1/(sin(x0)+1)^(1/2), (1/2)*2^(1/2)*(sin(x0)+1)^(1/2))+EllipticK((1/2)*(2*sin(x0)+2)^(1/2)))*2^(1/2)

eval(raw, x0=0.1);

.448035371*2^(1/2)

Download earlier_integral.mw

[edit] In fact the same well-behaved exact form can be obtained even more directly. (The key here is to also pass the assumption x0>0.)

int(1/sqrt(sin(x0)-sin(x)),x=0..x0) assuming x0>0, x0<Pi/2;

2^(1/2)*EllipticK((1/2)*(2*sin(x0)+2)^(1/2))-2^(1/2)*EllipticF(1/(sin(x0)+1)^(1/2), (1/2)*(2*sin(x0)+2)^(1/2))

 

I wouldn't be surprised if there is a more direct way.

r := x*(diff(theta(t), t))^2+y*(diff(varphi(t), t))^2;

x*(diff(theta(t), t))^2+y*(diff(varphi(t), t))^2

g := (4*(f+T))*(diff(theta(t), t))^2+u*(diff(varphi(t), t))^2;

4*(f+T)*(diff(theta(t), t))^2+u*(diff(varphi(t), t))^2

solve(identity(subsindets(r=g,specfunc(diff),freeze),
               freeze(diff(theta(t),t))),
      [x,y]);

[[x = 4*T+4*f, y = u]]

Download solve_id_diff.mw

The above works by changing the diff calls into mere names, so that one of them can be used as the second argument within the identity(...). A variant might be,

solve(identity(subsindets(r=g,specfunc(diff),freeze),
               freeze(indets(r=g,specfunc(diff))[1])),
      [x,y]);

You referred to additional, "complicated" cases. It's often much easier to provide a usefully extensible answer if you provide more than your simplest example.

ps. For that call to solve, you could optionally pass [x,y,T,f,u] instead of just [x,y], etc.

First 48 49 50 51 52 53 54 Last Page 50 of 309