acer

32313 Reputation

29 Badges

19 years, 310 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

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.

Having all those individual elementwise operations seems overly complicated (and as seen, somewhat error prone), especially in 2D Input mode.

It's also less efficient, I suspect, since using it produces lots of collectible garbage Vectors unnecessarily.

Instead, you could simply construct a single operator that acts on scalars, and then apply that elementwise to your pair of Vectors.

restart

V2 := Vector(5, {(1) = 225.9, (2) = 161.7, (3) = 147.2, (4) = 215, (5) = 207})

V1 := Vector(5, {(1) = 31.6, (2) = 30.3, (3) = 32.6, (4) = 35, (5) = 32.7})

sm := proc (pp, tta) options operator, arrow; pp*10^((5.49*pp^3.88/10^11+0.71e-1)*(tta-37)/(9.72*pp^3.88/10^9+2.30)) end proc

`~`[sm](V2, V1)

Vector[column](%id = 18446884434444422550)

sm(225.9, 31.6)

201.0101264

The correct values of the calculation should be

 

Correct := Vector(5, {(1) = 201.01, (2) = 127.38, (3) = 123.015, (4) = 205.284, (5) = 186.373})

Vector[column](%id = 18446884434444418454)

``

Download Elementwise_ac.mw

note: I would often prefer a scalar operator (used as a single elementise operation) then a whack of visually confusing typeset elementwise operations in 2D Input, even if it were less efficient (and I suspect it sometimes isn't). Opinions may vary...

ps. Here you might also use zip(sm,V2,V1) instead of sm~(V2,V1) .

You can simply declare the name a as local to the procedure, without the type being part of that declaration. You don't have to add types to any local declarations. For example,

   proc(...)
      local a, b;
      a := Array(...);
      b := [...];
    ...
    end proc

The special type declaration of locals is only enforced (when the procedure gets subsequently called) if the assertion-level check is set high enough (which it is not, by default).

For the Description of the Help page for Topic procedure:

     Local variables that appear in the local localSequence; clause may optionally be followed
     by :: and a type. As in the case of the optional returnType, this is not a type declaration, but
     rather an assertion. If kernelopts(assertlevel) is set to 2, any assignment to a variable
     with a type assertion is checked before the assignment is carried out. If the assignment
     violates the assertion, then an exception is raised.

By default the value of kernelopts(assertlevel) is 0. So by default such types specified in local declarations are not checked. They can be present, whether checked or not. You have to issue kernelopts(assertlevel=2) to have them get checked when the procedure gets called (run).

The presence of the types in local declarations in your custom procedures is optional. Whether such types are checked is also optional (and can be enabled/disabled by command).

Does that make it clear?

First 75 76 77 78 79 80 81 Last Page 77 of 336