acer

32303 Reputation

29 Badges

19 years, 309 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Is this the kind of thing you're trying to accomplish?

note: I realize that I could have used mod (or iquo,irem), to handle your integer examples. But I wanted to give you something that you might also use for floating-point angles. I'm not sure how you plan to use any results, however...
 

NULLMesure prinicipale

 

" in ]-Pi;Pi] "

 

NULL

restart

randomize()

with(plots)

L := [seq(-720 .. -30, 15), seq(360 .. 720, 15)]

"with(Student[Statistics]):"

X := EmpiricalRandomVariable(L)

Da := Sample(X, 1)[1]

495

Ra := ((1/360)*Da*2)*Pi

(11/4)*Pi

f := x -> (1/180*x - 2*round(1/360*x))*Pi:

f(Da);

(3/4)*Pi

 

 

 

DV := Sample(X, 100); DVf := map(proc (x) options operator, arrow; [x, f(x)] end proc, DV); plots:-pointplot(DVf)

NULL

Download QuestionMesPrincipale_ac.mw

You have the code,

for j from 1 to m-1 do
  for i from 0 to n-1 do
   u[i,j+1]:=(9*u[i-1,j]+14**u[i,j]+9*u[i+1,j])/16-u[i,j-1];
  end do;
end do:

That inner loop starts at i=0, but the lower bound of the first index of array u is 0, so you have an error when that loop tries to access u[i-1,j]. That index value becomes i-1=-1 when i=0, and is less than the lower bound 0. And so that access attempt is out-of-bounds. It's trying to access an element of u which does not exist. Perhaps you intended something like,
  for i from 1 to n-1 do
instead.

There is also an insteance of [i]/10 in the code. But [i] makes a list. Your code tries to add that to scalar values. Did you really intend for that? Perhaps you intended just i/10 instead?

There is also an instance of 4**u[i,j] in the code. The double-asterisk is syntax for powering, eg.  x**2 = x^2.  I suspect you intended just 4*u[i,j].

You could simply use mul to multiply together the finite (and concrete) number of terms, instead of stuffing in unevaluation quotes to try avoiding premature evaluation under product.

note. You could also use just Matrix(3,f) instead of Matrix(3,(i,j)->f(i, j)). And the entries are already floats, so you don't need to wrap it with evalf.

restart; randomize():

D1 := evalf(LinearAlgebra:-RandomMatrix(3));

D1 := Matrix(3, 3, {(1, 1) = -79., (1, 2) = 74., (1, 3) = 57., (2, 1) = 50., (2, 2) = -96., (2, 3) = 57., (3, 1) = -31., (3, 2) = 30., (3, 3) = 73.})

f := (i, j) -> if i = j then D1[i, i];
               elif i = j + 1 then
                 (1 - abs(D1[i, i])^2)^(1/2)*(1 - abs(D1[j, j])^2)^(1/2);
               elif j + 1 < i then
                 (1 - abs(D1[i, i])^2)^(1/2)
                 * (1 - abs(D1[j, j])^2)^(1/2)
                 * mul(-conjugate(D1[t, t]), t = j + 1 .. i - 1);
               else 0; end if:

Matrix(3, (i, j) -> f(i, j));

Matrix([[-79., 0, 0], [-7582.980944, -96., 0], [-553535.7002, -7006.962252, 73.]])

Download rzarouf_ac.mw

Is this the kind of 2D Input (from palettes) that you'd care to manipulate with the Logic package?

restart

L := module() option package;
   export `implies`:=Logic:-`&implies`;
   export `iff`:=Logic:-`&iff`; export `not`:=Logic:-`&not`;
   export `and`:=Logic:-`&and`; export `or`:=Logic:-`&or`;
end module:

with(Logic)with(L)

 

iff(not (P or Q), `and`(not P, not Q))

Logic:-`&iff`(Logic:-`&not`(Logic:-`&or`(P, Q)), Logic:-`&and`(Logic:-`&not`(P), Logic:-`&not`(Q)))

Tautology(%)

true

S1 := not (P or Q)

Logic:-`&not`(Logic:-`&or`(P, Q))

S2 := `and`(not P, not Q)

Logic:-`&and`(Logic:-`&not`(P), Logic:-`&not`(Q))

Tautology((S1 implies S2) and (S2 implies S1))

true

Normalize(S1)

Logic:-`&and`(Logic:-`&not`(P), Logic:-`&not`(Q))

Normalize(not S2)

Logic:-`&or`(P, Q)

 

iff(not (P and Q), `or`(not P, not Q))

Logic:-`&iff`(Logic:-`&not`(Logic:-`&and`(P, Q)), Logic:-`&or`(Logic:-`&not`(P), Logic:-`&not`(Q)))

Tautology(%)

true

S3 := not (P and Q)

Logic:-`&not`(Logic:-`&and`(P, Q))

S4 := `or`(not P, not Q)

Logic:-`&or`(Logic:-`&not`(P), Logic:-`&not`(Q))

Tautology((S3 implies S4) and (S4 implies S3))

true

Normalize(S3)

Logic:-`&or`(Logic:-`&not`(P), Logic:-`&not`(Q))

Normalize(not S4)

Logic:-`&and`(P, Q)

Download Logic_2DInput.mw

note: You can unwith(L) if you subsequently need to turn off L's rebindings, for other inputs. Also, you can always utilize the original globals in prefix form, eg. :-`not`(a):-`or`(a,b) though it's more wordy.

[edited] It might be suitable if 2D Input of the relevant items in the palettes got interpreted directly as the corresponding Logic package exports if that package were loaded. That's what loading the small module L provides.

In your Question's text you stated that you want to change it, "...by replacing  vin/Iout with omega0*Lm". But then later you showed the attempt,

   eval(sol1, vin/Iout = omega*Lm)

which has omega rather than omega0. I'm going to proceed as if that attempt were a typo.

The algsubs command can perform that initial substitution.

sol1 := C*vout*vin/(Iout*L*k^2);

C*vout*vin/(Iout*L*k^2)

algsubs(vin/Iout = omega0*Lm, sol1);

C*vout*omega0*Lm/(L*k^2)

eval(%, [Lm = k*L, C = 1/(omega0*L)]);

vout/(L*k)

Download jrive_ex4.mw

I suggest that you double-check all your formulas.

I fix that kind of error by using a full colon as statement terminator.

It's slightly difficult to see exactly what your after, since s does not appear in your expression assigned to V, and that expression also contains a term R1_R2. I'll proceed below as if those are mere typos.

Perhaps it is something like the following?

V := V1*R2/(C*R1*R2*s+R1+R2);

V1*R2/(C*R1*R2*s+R1+R2)

We are going to try to reformulate the expression assigned
to V, in the following form.

target := V1*R2/(R1+R2)/(C*R1*R2*s/(R1+R2)+1);

V1*R2/((R1+R2)*(C*R1*R2*s/(R1+R2)+1))


The OP has asked that we do that as, "divide numerator and
denominator by the s^0 coefficient." [presumably of the denominator]

The job is easily done, in only two steps.

The first step is to obtain the s^0 coefficient in the
denominator. We get it programmatically, not by eye.

 

F0 := coeff(denom(V),s,0);

R1+R2

numer(V)/F0  /  collect(denom(V)/F0,s);

V1*R2/((R1+R2)*(C*R1*R2*s/(R1+R2)+1))

We happen to get the desired ordering of terms
in the sums in the denominator (ie. the "1" on the right), forced
because I'd 
already input the target expression in the same session.

If I hadn't entered the target formula, we might also
need this sorting of terms in the sum, for prettiness.

#sort( %, order=plex(s) );

Download jrive_ex3.mw

The andmap's purpose here is to bail (returning false) upon the first entry discovered as false. That's for efficiency.

But that could be done at both levels, here, ie. per equation as well as per soln value. In general that's even more efficient, as it would return the single false result as soon as any one instantiated equation were found to be false.

restart;

kernelopts(version);

`Maple 2022.2, X86 64 LINUX, Oct 23 2022, Build ID 1657361`

eqs := [u     + v     + w     = 1,   u*x   + v*y   + w*z   = 1/2,
        u*x^2 + v*y^2 + w*z^2 = 1/3, u*x^3 + v*y^3 + w*z^3 = 1/4,
        u*x^4 + v*y^4 + w*z^4 = 1/5, u*x^5 + v*y^5 + w*z^5 = 1/6]:

soln := [solve(eqs, explicit)];

[{u = 4/9, v = 5/18, w = 5/18, x = 1/2, y = 1/2+(1/10)*15^(1/2), z = 1/2-(1/10)*15^(1/2)}, {u = 4/9, v = 5/18, w = 5/18, x = 1/2, y = 1/2-(1/10)*15^(1/2), z = 1/2+(1/10)*15^(1/2)}, {u = 5/18, v = 4/9, w = 5/18, x = 1/2+(1/10)*15^(1/2), y = 1/2, z = 1/2-(1/10)*15^(1/2)}, {u = 5/18, v = 4/9, w = 5/18, x = 1/2-(1/10)*15^(1/2), y = 1/2, z = 1/2+(1/10)*15^(1/2)}, {u = 5/18, v = 5/18, w = 4/9, x = 1/2+(1/10)*15^(1/2), y = 1/2-(1/10)*15^(1/2), z = 1/2}, {u = 5/18, v = 5/18, w = 4/9, x = 1/2-(1/10)*15^(1/2), y = 1/2+(1/10)*15^(1/2), z = 1/2}]

andmap(s->andmap(is,s),map[2](eval,eqs,soln));

true

By putting all the instantiated equations into a single container
then a single call to andmap suffices.

For this particular problem that single container can be reduced
merely by making it a set (some instantiations are duplicates...).

andmap(is,map[2](op@eval,eqs,{soln[]}));

true

Download andmap_ex.mw

As fun bonus, there happens to be no seq variable in play, to be declared local...

restart;

Lm := (simplify(k*sqrt(L*L)) assuming (0 < L));

k*L

L1 := (factor(L - Lm) assuming (0 < L and 0 < Lm and 0 <= k));

-L*(k-1)

sort(collect(L1,L),k,':-ascending');

(1-k)*L

Download jrive_ex.mw

Note what happens without the sort (I have to do it in a fresh session, since the sorted result in the session above is subsequently obtainable without it...).

restart;

Lm := (simplify(k*sqrt(L*L)) assuming (0 < L)):

L1 := (factor(L - Lm) assuming (0 < L and 0 < Lm and 0 <= k)):

collect(L1,L);

(-k+1)*L

sort(%,k,':-ascending');

(1-k)*L

Download jrive_ex2.mw

ps. If you have more involved examples then please show them up front in your Question.

If you merely use single right-tick uneval quotes (As Carl's suggested) then subsequent full evaluation of the resulting plot structure can lead to inadvertant and undesirable evaluation of assigned names in the textplots.

That can include the scenario where you pass the textplot(s) to plots:-display as a subsequent programmatic merging with plots computed only later.

That can make merely using uneval quotes a somewhat problematic approach. Too few layers of quoting and your code might accidentally evaluate the quoted expressions. Too many layers and some quotes can undesirably appear in the rendering. Too tricky, and fragile if mixed with later revisions to the overall code.

Passing the resulting assigned textplot structure around as eval(P,1) is possible, but that too can get complicated and onerous -- depending on later code changes.

Instead, your could use Typesetting:-Typeset to get the textplots, with much better resistence to such unwanted subsequent evaluation. Basically, it's just going to be more robustly useful in such a case that you don't want any part of the "text" to be subsequently, accidentally evaluated. You only have to focus on its construction, and not on how you use/pass it later.

In the examples below, the green text survives as intended, while the red text goes wrong due to inadvertant evaluation.

restart;

with(plots): setoptions(size=[500,300]);

 

p,c := -2,5;

-2, 5

P := display(
  textplot([1,3,Typesetting:-Typeset(p<c)], color="Green"),
  textplot([1,2,':-p'<':-c'], color="Red"),
  view=0..4);

P;

display(P, plot((x-4)^2,x=0..8));


Download textplot_TT.mw

nb. If your expression is first assigned to some name, eg.  foo:=expression , then you might need either,
   Typesetting:-Typeset(Typesetting:-EV(foo))
or,
   eval('Typesetting:-Typeset'(eval(foo,1)))
etc, since Typesetting:-Typeset has special evaluation rules (to prevent automatic evaluation) on its first parameter.
textplot_TT_2.mw

A call like,

   DocumentTools:-GetProperty("ComboBox0", value);

will return the currently selected item in the Combo Box embedded component with that ID.

The command parse would turn that string into the global instance of a name (if valid as such).

CB_ex1.mw

There are examples of this kind of use of GetProperty on this Help page. (That page was the very first hit, when I entered ComboBox in the Help Browser's search field.)

The parse command is not specific to embedded components. You could also be more verbose with, say, convert(str,name), btw.

An even more typical scenario for such use of parse is getting user-supplied numeric values from a TextBox embedded component. In that case, the Help page's main example actually uses parse, which is helpful. In the case of a ComboBox any programmatic contextual switching could be string-based as well/easily as name-based, by which I mean that parsing to a name isn't so inherently useful because the choices were already hard-coded and known the code author.

I was able to recover the following. Please check it over.

There might be an equation or Matrix input missing after the line containing, "Til at starte med bestemmer vi", and another after the line beginning, "Vi kan bestemme". And I'm not sure whether the very first opening Section should contain all other Sections (you might need to adjust).

Auto_regne_dokument_acc.mw

This kind of curruption problem seems to be less frequent with Maple 2023. You might want to try that upgrade, if available to you.

In any event, I suggest that you try to make regular backups -- even if that means saving to separate files, manually.

The z that is the named parameter of your procedure,
    v := z -> functionList[1]
has nothing to do with the global name z that is in the expressions in the set. That's why your attempt does not succeed; invoking that procedure does not replace the z in the expression.

Here are two ways, the second a correction to your procedure-building approach, and the first a simpler approach using eval.

restart;

functionList := {2 + z, z^2 - 3*z, -z^3 + 4}:


Easier way, IMO.

plot3d(Im(eval(functionList[1],z=x + y*I)), x = -1 .. 1, y = -1 .. 1);

v := unapply(functionList[1],z):

plot3d(Im(v(x + y*I)), x = -1 .. 1, y = -1 .. 1);


Note that the following produce the same result as each other,
and are both what can get passed straight to plot3d as its
first argument (if you were to use the second element of your set).

The first method is considerably simpler. It is unnecessary
extra effort to construct a procedure/operator v
and then to only call it once (merely to construct the argument
passed to plot3d).

Im(eval(functionList[2],z=x + y*I))

Im((x+I*y)^2-3*x)-3*Re(y)

v := unapply(functionList[2],z):
Im(v(x + y*I));

Im((x+I*y)^2-3*x)-3*Re(y)

Download unapp_ex.mw

Is this one of the kinds of animation of the curves that you mean?

See attachment for animation of t vs x(t), t vs y(t), with all three playable together and axes aligned. Adjust as wanted.

caring_phase_pemanenan_predator_dgn_parametersesuai_jurnal_ac.mw

There seem to be quite a few "corner cases", what with automatic-simplification, GUI rendering quirks, etc.

(I did this quickly, without cleaning it up. Check for mistakes...)

restart;

H := proc(ee) local res;
  res := subsindets(combine(simplify(ee)),`*`^fraction,
                    proc(u)
                       `if`(denom(op(2,u))=2,
                            surd(op(1,u)^numer(op(2,u)),denom(op(2,u))),
                            %surd(op(1,u)^numer(op(2,u)),denom(op(2,u))));
                    end proc)
         assuming positive;
  subsindets(res, {name,name^integer}^fraction,
             proc(u) local p,r,res; uses ID=InertForm:-Display;
               p := iquo(numer(op(2,u)),denom(op(2,u)),'r');
               if denom(op(2,u))=2 then
                 (op(1,u)^p)*ID((op(1,u)%^(r/denom(op(2,u)))),
                                'inert'=false);
               else
                 (op(1,u)^p)*surd((op(1,u)^r,denom(op(2,u))));
               end if;
             end proc);
end proc:

 

 

H(sqrt(a^3*b^5))

a*b^2*(a*b)^(1/2)

H(sqrt(x^6*y^5*z^5))

x^3*y^2*z^2*(y*z)^(1/2)

H(sqrt(x^6*y^4*z^5))

0, "%1 is not a command in the %2 package", _Hold, Typesetting

H(sqrt(x^6*y^5*z^4))

0, "%1 is not a command in the %2 package", _Hold, Typesetting

H((a^4*b^7*c^3)^(1/3))

a*b^2*c*%surd(a*b, 3)

H((a^4*b^6*c^3)^(1/3))

a*surd(a, 3)*b^2*c

H((a^4*b^8*c^3)^(1/4))

a*b^2*surd(c^3, 4)

H((a^9*b^8*c^3)^(1/4))

a^2*b^2*%surd(a*c^3, 4)

H((a^8*b^8*c^2)^(1/4))

0, "%1 is not a command in the %2 package", _Hold, Typesetting

H((a^9*b^8*c^2)^(1/4))

0, "%1 is not a command in the %2 package", _Hold, Typesetting

H((a^9*b^2*c^2)^(1/4))

a^2*surd(a, 4)*(b*c)^(1/2)

Download example_2_acF.mw

First 36 37 38 39 40 41 42 Last Page 38 of 336