acer

32373 Reputation

29 Badges

19 years, 333 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

I found it by looking at the list of extra options on the ?dsolve,numeric,DAE Help page's Description section.

Near a mention of the differential option, that page had a cross-reference link to the ?dsolve,numeric,DAE_extension Help page, which contains the details of these extension methods for the numeric DAE solvers.

The default extent of the axis view comes from the data points themselves (or a fitted curve).

You can override it by using the usual view option for plotting commands.

For example,

restart; with(Statistics):
N:=200: U:=Sample(Normal(0,1),N):
X,Y:=<seq(1..N)>,<seq(sin(2*Pi*i/N)+U[i]/5,i=1..N)>:
ScatterPlot(X,Y,view=[-20..220,-2..2]);
ScatterPlot(X,Y,view=[-20..220,default]);
ScatterPlot(X,Y,view=[default,-2..2]);

The first sentence in the Options section of the ScatterPlot Help page (Maple 2018) states, with a cross-reference link to the Help page for plot options, "The options argument can contain one or more of the options shown below. All unrecognized options will be passed to the plots[display] command. See plot[options] for details."

What that means is that most of the 2D plotting command common options can be simply passed straight into calls to the ScatterPlot command.

 

restart;

eq:=diff(a(t),t)/a(t)=alpha*t:

T1:=dsolve({eq,a(0)=1}):

de:=diff(lambda(t),t)=rhs(T1):

T2:=dsolve({de,lambda(0)=0}):

SS:=exp(-lambda^2/(2*tau^2))*1/(sqrt(2*Pi)*tau):

SSS:=combine(eval(SS*alpha/rhs(T1),[lambda=rhs(T2),
                                    tau=eval(rhs(T2),t=b)]))
  assuming alpha::positive, b::positive:

expr:=simplify(eval(SSS,[alpha=0.1,b=0.1]));

.3988757910*exp(785.1363895*erf((.2236067978*I)*t)^2-0.5e-1*t^2)

CodeTools:-Usage(
  2*evalf(Int(unapply('evalf[15]'(expr),t),0..infinity,method = _d01amc))
);

memory used=5.23MiB, alloc change=0 bytes, cpu time=37.00ms, real time=36.00ms, gc time=0ns

0.9990021586e-1

Download OverflowError_ac.mw

An alternative to dharr's nice idea, for this example, is to selectively utilize limit.

Naturally, it's not as fast as dharr's switch. But I didn't have to consider the form.

restart;

kernelopts(version);

`Maple 2015.2, X86 64 LINUX, Dec 20 2015, Build ID 1097895`

with(plots):

G0 := y -> exp(y)/(1+exp(y)):
w  := (z, p, q) -> sin(p^+ . z) / (1 + cos(q^+ . z)):

K := 2:
X := Vector(K, symbol=x):
P := `<,>`(2, 1):
Q := `<,>`(0, 3/2):
Modulation := G0(w(X, P, Q)):
pdf        := exp(-1/2 * X^+ . X) / (2*Pi)^(K/2):
Gpdf       := 2*pdf*Modulation:

Gpdf2 := proc(x1,x2) local temp;
  if not [args]::list(numeric) then return 'procname'(args) end if;
  temp := eval(Gpdf,x[1]=x1);
  try eval(temp,x[2]=x2);
  catch: limit(temp,x[2]=x2,':-right');
  end try;
end proc:

opts := grid=[200, 100], contours=[seq(0.01..0.2, 0.02)],
        color=blue, axes=boxed, gridlines=true:
contourplot(Gpdf2(x[1],x[2]), x[1]=-3..3, x[2]=-3..3, opts);

display(
  seq(implicitplot(Gpdf2(x[1],x[2])=level, x[1]=-3..3, x[2]=-3..3,
                   color=blue, gridrefine=3),
      level in eval(contours,[opts])));

 

Download Discontinuous_contours_ac.mw


ps. for implicitplot this use of gridrefine=3 above seems to produce a slightly nicer result that the original gridrefine=4 does there.

Your other set of contour values is also improved:

opts2 := grid=[200, 100], contours=[seq(0.01..0.04, 0.0025)],
        color=blue, axes=boxed, gridlines=true:
contourplot(Gpdf2(x[1],x[2]), x[1]=-3..3, x[2]=-3..3, opts2);

display(
  seq(implicitplot(Gpdf2(x[1],x[2])=level, x[1]=-3..3, x[2]=-3..3,
                   color=blue, gridrefine=3),
      level in eval(contours,[opts2])));

 

You can do this simply by indexing into C.

You shouldn't be using the deprecated linalg:-bloackmatrix to construct C. That also produces a deprecated lowercase matrix, by the way. You can use the <...> constructor instead, which here produces a Matrix.

I've edited my response to include the possibility that you'd want to make the V[i] into columns of a Matrix.

restart;

V[1],V[2],V[3] := Vector([3, 2, -4]),
                  Vector([1, 2/3, 7]),
                  Vector([-9, 0, 1/2]);

V[1], V[2], V[3] := Vector(3, {(1) = 3, (2) = 2, (3) = -4}), Vector(3, {(1) = 1, (2) = 2/3, (3) = 7}), Vector(3, {(1) = -9, (2) = 0, (3) = 1/2})

C := <V[1],V[2],V[3]>;

C := Matrix(9, 1, {(1, 1) = 3, (2, 1) = 2, (3, 1) = -4, (4, 1) = 1, (5, 1) = 2/3, (6, 1) = 7, (7, 1) = -9, (8, 1) = 0, (9, 1) = 1/2})

C[1..3], C[4..6], C[7..9];

Matrix(3, 1, {(1, 1) = 3, (2, 1) = 2, (3, 1) = -4}), Matrix(3, 1, {(1, 1) = 1, (2, 1) = 2/3, (3, 1) = 7}), Matrix(3, 1, {(1, 1) = -9, (2, 1) = 0, (3, 1) = 1/2})

seq(C[(i-1)*3+1..i*3], i=1..3);

Matrix(3, 1, {(1, 1) = 3, (2, 1) = 2, (3, 1) = -4}), Matrix(3, 1, {(1, 1) = 1, (2, 1) = 2/3, (3, 1) = 7}), Matrix(3, 1, {(1, 1) = -9, (2, 1) = 0, (3, 1) = 1/2})

F := n->C[(n-1)*3+1..n*3]:

F(1),F(2),F(3);

Matrix(3, 1, {(1, 1) = 3, (2, 1) = 2, (3, 1) = -4}), Matrix(3, 1, {(1, 1) = 1, (2, 1) = 2/3, (3, 1) = 7}), Matrix(3, 1, {(1, 1) = -9, (2, 1) = 0, (3, 1) = 1/2})

M := <V[1]|V[2]|V[3]>

M := Matrix(3, 3, {(1, 1) = 3, (1, 2) = 1, (1, 3) = -9, (2, 1) = 2, (2, 2) = 2/3, (2, 3) = 0, (3, 1) = -4, (3, 2) = 7, (3, 3) = 1/2})

M[..,1], M[..,2], M[..,3]

Vector(3, {(1) = 3, (2) = 2, (3) = -4}), Vector(3, {(1) = 1, (2) = 2/3, (3) = 7}), Vector(3, {(1) = -9, (2) = 0, (3) = 1/2})

Download Vec_indx.mw

Sure, you could apply log10 to the x and (discarding negatives) the y values. Then force new tickmarks by powering 10, then set the axis locations to `low`, etc. But getting realy nice smooth curves by adaptive sampling becomes tricky. Why reinvent that wheel?

You can compare the loglogplot result with a plot call specifying mode=log for both axes.

I've added gridlines. Notices that the log mode does occur for the vertical axis, though the values are close enough to make the effect less apparent.

loglog_ac.mw

The expressions log[10](R) and log10(R) will both evaluate to ln(R)/ln(10). So the change occurs even before solve get's its arguments.

You may use the inert version instead. You can utilize the value command later, if you'd like.

For example (using %log[10] since you used log[10], though it's similar with %log10 ),

expr := sqrt(%log[10](R)/T) = a+b*%log[10](R)

(%log[10](R)/T)^(1/2) = a+b*%log[10](R)

solve(expr, T) = %log[10](R)/(%log[10](R)^2*b^2+2*%log[10](R)*a*b+a^2)NULL

factor(%)

%log[10](R)/(a+b*%log[10](R))^2

value(%)

ln(R)/(ln(10)*(a+b*ln(R)/ln(10))^2)

NULL

Download log10_ac.mw

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...

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