acer

32405 Reputation

29 Badges

19 years, 351 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The very first line of the Description of the Help page for Topic error refers to it as the "error statement".

There are other kinds of statement, for example the selection (conditional) statement and the repetition statement. Those also do not require brackets in that they are not called like functions (though delimiting brackets to establish grouping or operator precedence may be used).

There is also an older (deprecated) ERROR function, which is called with brackets denoting the functional application.

So I disagree with your claims, citing the above as evidence. You don't call error with a functional application because it is offered as a statement rather than a functional call. And there are indeed other kinds of statements which also can be made without a functional call, and which also do not always require bracketing (either as delimiters or to denote a functional call).

[edit] You wrote that the syntax for error is, "...different from all other Maple functions". That's because error is not called like a function, so it doesn't make sense to compare it with "other" functions. The brackets in your second example don't change the nature of the statement.

Perhaps it would help to think of error as a language keyword.

You could consider the error statement and the (old, deprecated) ERROR function along with the return statement and the (old, deprecated) RETURN function.

You can save a few characters with,

    ['A'[..,i]$i=1..4]

If you want a re-usable procedure (for Matrices of general size) then you can do as follows (this too is shorter than using seq, and so is terser than Kitonum's suggestion).

F:=A->['A[..,i]'$i=1..op([1,2],A)]:

A:=Matrix([[1,2,1,3,2],[3,4,9,0,7],[2,3,5,1,8],[2,2,8,-3,5]]):

F(A);

[Vector(4, {(1) = 1, (2) = 3, (3) = 2, (4) = 2}), Vector(4, {(1) = 2, (2) = 4, (3) = 3, (4) = 2}), Vector(4, {(1) = 1, (2) = 9, (3) = 5, (4) = 8}), Vector(4, {(1) = 3, (2) = 0, (3) = 1, (4) = -3}), Vector(4, {(1) = 2, (2) = 7, (3) = 8, (4) = 5})]

Download cols_list_proc.mw

You wrote, "...i assign stepsize to have accurate results". That is untrue -- a small fixed step-size does not -- in itself -- guarantee better accuracy.

If you are going to do something as forcing and, in my opinion, unjustified as fix a very small step-size then you may well have to raise the limit on functional evaluations.

Your call to plot of GAM(tau) suppresses the warnings about exceeding the maxfun value. You could do better here to instead use the plots:-odeplot command, which as seen below would have informed you through a warning of the problem stemming from your forced small step-size, even without raising infolevel.

But even calling GAM for tau values further toward the right end-point can show you that problem. It makes sense to test your solution, when you encounter difficulties.

restart:

with(DEtools):

#constants
a0 := 10:sigma := 100: theta := (1/4)*Pi:L := 80000:omegace:=0:
#Differential Equations
Eq1:= diff(Rhoy(tau),tau)=-gam(tau)*(Z(tau)/(L))*Y(tau)+sin(theta)*(((1/2)*a0*exp(xi(tau)-400)/sigma^2)*diff(xi(tau),tau))-(omegace/omega)*Rhoz(tau):
Eq2:=diff(Rhoz(tau),tau)=(((1/2)*a0*exp(xi(tau)-400)/sigma^2)*cos(theta)^2+Rhoy(tau)*sin(theta))*((1/2)*a0*exp(xi(tau)-400)/sigma^2)*(1)+(omegace/omega)*Rhoy(tau):
Eq3:=diff(Y(tau),tau)=Rhoy(tau):
Eq4:=diff(Z(tau),tau)=Rhoz(tau):
Eq5:=diff(xi(tau),tau)=gam(tau)-Rhoz(tau):
Eq6:=diff(gam(tau), tau) = (1/4)*(2*a0^2*(exp(xi(tau)-400))^2*cos(theta)^2*(diff(xi(tau), tau))/sigma^4+8*Rhoy(tau)*(diff(Rhoy(tau), tau))+8*Rhoz(tau)*(diff(Rhoz(tau), tau)))/sqrt(4+a0^2*(exp(xi(tau)-400))^2*cos(theta)^2/sigma^4+4*Rhoy(tau)^2+4*Rhoz(tau)^2):
sys:=seq(Eq||i,i=1..6):
#initial conditions
inits:=xi(0)=400,gam(0)=1,Z(0)=0,Y(0)=0,Rhoz(0)=0,Rhoy(0)=0:
#sol:=dsolve([sys,inits]);
sol:=dsolve([sys,inits],numeric,output=listprocedure):
GAM:=eval(gam(tau),sol):
XI:=eval(xi(tau),sol):
plot([GAM(tau)/51],tau=0..10,axes=boxed,gridlines,color=[blue,red]);
#GAM(tau) is between 0 to 1.2

sol1:=dsolve([sys,inits],numeric,stepsize=1e-5,output=listprocedure):
GAM:=eval(gam(tau),sol1):
XI:=eval(xi(tau),sol1):

GAM(1.7);

Error, (in GAM) cannot evaluate the solution further right of 0.50000000e-1, maxfun limit exceeded (see ?dsolve,maxfun for details)

infolevel[dsolve]:=2;
plot([GAM(tau)/51],tau=0..10,axes=boxed,gridlines,color=[blue,red]);
infolevel[dsolve]:=0;

2

dsolve/numeric/SC/IVPrun: error - exceeded maxfun limit

dsolve/numeric/SC/IVPrun: to go farther, restart with maxfun larger than  30000

0

plots:-odeplot(sol1,[tau,GAM(tau)/51],tau=0..10,axes=boxed,gridlines,color=[blue,red]);

Warning, cannot evaluate the solution further right of .50000000e-1, maxfun limit exceeded (see ?dsolve,maxfun for details)

Error, (in GAM) cannot evaluate the solution further right of 0.50000000e-1, maxfun limit exceeded (see ?dsolve,maxfun for details)

sol2:=dsolve([sys,inits],numeric,stepsize=1e-5,output=listprocedure,maxfun=10^8):
GAM2:=eval(gam(tau),sol2):
XI2:=eval(xi(tau),sol2):
plot([GAM2(tau)/51],tau=0..10,axes=boxed,gridlines,color=[blue,red]);

 

Download dsolve_stepsize.mw

note: There are other reasons to use plots:-odeplot. It contains some extra smarts to try and use independent variable values dictated in part by the solver, as opposed to just calling plot and having its adaptive algorithm try and pepper the space as it wants. Just my opinion.

You have mentioned doing the "operation in reverse by hand". If that entails applying tan both sides of the equation (after isolating) then note that is not generally valid.

It does not following that A=B just because tan(A)=tan(B).

eq :=-Pi/2 - arctan(25*x) - Pi = - 2*Pi/3;

-(3/2)*Pi-arctan(25*x) = -(2/3)*Pi

isolate(eq, arctan(25*x));

arctan(25*x) = -(5/6)*Pi

map(tan, %);  # not ok!

25*x = (1/3)*3^(1/2)

%/25;

x = (1/75)*3^(1/2)

 

Is this the kind of thing you are trying to accomplish?

Note that (the way the conditional if..then inside your procedure lambda22sol is set up), if you call procedure lambda22sol a second time without unassigning __old_a then it will return NULL. I suspect that is why you got that error message, because you were calling it twice and so the middle column of matrix1 from the call lambda22sol(0.9) was NULL.

restart;

data:=ExcelTools:-Import(cat(kernelopts(homedir),"/mapleprimes/","data.xlsx")):

with(LinearAlgebra):
lambdaX:=Column(data,1):
PK1X:=Column(data,2):


tensF:=Matrix([[lambda11,0,0],[0,lambda22,0],[0,0,lambda22]]):
tensFbar:=Matrix([[(lambda11/lambda22)^(2/3),0,0],[0,1/sqrt((lambda11/lambda22)^(2/3)),0],[0,0,1/sqrt((lambda11/lambda22)^(2/3))]]):
tensBbar:=Multiply(tensFbar,Transpose(tensFbar)):

kappa:=100:
tensPK:=Multiply(Transpose(MatrixInverse(tensF)),(2/Determinant(tensF))*a*(tensBbar-(1/3)*Trace(tensBbar)*Matrix(3,shape=identity))+kappa*(Determinant(tensF)-1)*Matrix(3,shape=identity)):
PK1:=tensPK[1,1]:
eq:=0=tensPK[2,2]:

lambda22sol:=proc(aValue)
   global __old_a;
   local res, i, eq1, sol1, lambda22Est;
   if not [aValue]::list(numeric) then
      return 'procname'(args);
   end if;
   lambda22Est:=Vector(1..RowDimension(lambdaX)):
   eq1:=Array(1..RowDimension(lambdaX)):
   if __old_a<>aValue then
      __old_a:= aValue;
     for i from 1 to RowDimension(lambdaX) do
             eq1[i]:=eval(eq,[a=aValue,lambda11=lambdaX[i]]):
                sol1:=[fsolve(eq1[i], lambda22)];
                lambda22Est[i]:=sol1[1]:
        end do:
        res:=lambda22Est;
   end if;
end proc:

__old_a:='__old_a':
LL:=lambda22sol(0.9):
matrix1:=<lambdaX|LL|PK1X>:

DS1:=CodeTools:-Usage(
        DirectSearch:-DataFit(abs(PK1),matrix1,[lambda11,lambda22]));
res2:=eval(PK1,DS1[2]):

memory used=9.71MiB, alloc change=0 bytes, cpu time=118.00ms, real time=118.00ms, gc time=0ns

[HFloat(2.866379619163419), [a = HFloat(-0.4500000222184452)], 28]

plots:-display(
  plot3d(eval(PK1,DS1[2]),lambda11=min(lambdaX)..max(lambdaX),
                            lambda22=0.5..1.5,
         style=surface, transparency=0.5),
  plots:-pointplot3d(matrix1,color=red,thickness=3),
  view=min(PK1X)..max(PK1X)
);

 

Download lambda22sol.mw

restart;

H:=Int(simplify(1/(x-1)+sum((k+1)*x^k,k=0..2018)/sum(x^k,k=0..2019)),x);

Int(2020*x^2019/(x^2020-1), x)

eval(value(IntegrationTools:-Change(H,s=x^2020,s)),s=x^2020);

ln(x^2020-1)

Download int_ex.mw

 

In a sense, that could be broken down into steps:  int_ex2.mw
There I replaced the numbers 2018 and 2019 by symbolic names, temporarily, to prevent awkward expansion. The following also works directly:

simplify(int(1/(x-1)+sum((k+1)*x^k,k=0..N)
                     /sum(x^k,k=0..N+1),x));

               ln(x^(N+2)-1)

There is a form, on the Software Change Request page (linked from the Mapleprimes top "More" tab).

(Rewritten question is now asked here.)

The axis mode is part of the generated plot structure (set altogether as the value property of the embedded component), and not a property of the embedded component.

You can add axis[2]=[mode=log] to the dataplot command.

restart;

DetAnalysisNx2:=[seq(0..2,0.1)]:

DetAnalysisDeterm2:=map(x->exp(x^2),DetAnalysisNx2):

DocumentTools:-SetProperty("DeterminantenRaumPlot1",
                           value,
                           dataplot(DetAnalysisNx2, DetAnalysisDeterm2));

DocumentTools:-SetProperty("DeterminantenRaumPlot1",
                           value,
                           dataplot(DetAnalysisNx2,DetAnalysisDeterm2,
                                    axis[2]=[mode=log]));


Download log_mode.mw

restart;

expression1 := -cos(theta)/2 + sin(theta)*sqrt(3)/2;

-(1/2)*cos(theta)+(1/2)*sin(theta)*3^(1/2)

expression3 := convert(expression1, phaseamp, theta);

-cos(theta+(1/3)*Pi)

simplify(expression1 - expression3);

0

 

Download trig_phaseamp.mw

Yes, it can be done using plottools:-transform as follows,

f,g := 1,min(3,1/x):
P:=plot(f-g,x=0..maximize(1/y,y=1..3),filled):
plottools:-transform(unapply([x,y+g],[x,y]))(P);

Of course, you might be able to see that the upper end-point of the x-range is just 1, without having to compute that from maximize(1/y,y=1..3).

And so you might also write down either of these, directly. They each produce a plot with the region shaded.

plottools:-transform((x,y)->[x,y+min(3,1/x)])(plot(1-min(3,1/x),x=0..1,filled));

plottools:-transform((x,y)->[x,y+1])(plot(min(3,1/x)-1,x=0..1,filled));

You can refer to the global names as :-J and :-F, in order to avoid collision with the locals of the same names.

You can furthermore quote those global name references with uneval quotes, so as to protect against the case of their having been assigned values.

restart;

foo:=proc(A::Matrix)
local J,Q;
J,Q:=LinearAlgebra:-JordanForm(A,output=[':-J',':-Q']);
end proc:

A:=Matrix([[1,2],[3,4]]);

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 2, (2, 1) = 3, (2, 2) = 4})

foo(A);

Matrix(2, 2, {(1, 1) = 5/2-(1/2)*sqrt(33), (1, 2) = 0, (2, 1) = 0, (2, 2) = 5/2+(1/2)*sqrt(33)}), Matrix(2, 2, {(1, 1) = 1/2+(1/22)*sqrt(33), (1, 2) = (1/66)*(-3+sqrt(33))*sqrt(33), (2, 1) = -(1/11)*sqrt(33), (2, 2) = (1/11)*sqrt(33)})

 

Download JordanForm_proc.mw

ps. You could sensibly quote the keyword option 'output' as well, on similar grounds.

It's not your fault; there is a bug in the case of filledregions, a specified non-default number of contours, and the new legend mechanism.

I am supposing that you want the specified number of contours (20) as in the first plot below, but the visual look of the thicker color bars in the second plot below.

(I may be able to figure out a hot fix for the procedure, a bit later today...)

restart;

ee:=16.70196911*2^(1/2)*((x^2 + 0.1*y)/((1 - x)*(3*x^2 + 0.2*y)))^(1/2)
    /(4.373839156*(x^2 + 0.1*y)/((1 - x)*(3*x^2 + 0.2*y)) + 1)^(1/2),
    x = 0.001 .. 1, y = 0.001 .. 1:

opts:=thickness = 0, coloring = ["blue", "yellow"]:

plots:-display(
   plots:-contourplot(ee, contours = 20, opts, legend),
   plots:-contourplot(ee, contours = 20, opts, filledregions),
   legendstyle=[location=right], axes = "boxed", size=[550,500]);

plots:-display(
   plots:-contourplot(ee, opts, filledregions, legend),
   legendstyle=[location=right], axes = "boxed", size=[550,500]);

 

Download filled_cont_legend_bug.mw

You are getting bitten by premature evaluation of the call f(x).

The error would occur even if you tried just to compute this,

    f(x);

Either use the functional calling sequence of the plot command, or pass 'f(x)' quoted so as to delay evaluation, or edit procedure f so that it returns unevaluated for nonnumeric x (I haven't done that last one).

restart;

sine :=   plot(sin(x), x=0..4*Pi, color=black,thickness=3):
s    :=   plot(sin(x), x=0..4*Pi, color=red, filled=true):
cosine := plot(cos(x), x=0..4*Pi, color=black,thickness=3):
c      := plot(cos(x), x=0..4*Pi, color=red, filled=true):

f := x -> if cos(x)>0 and sin(x)>0 then
              min(cos(x),sin(x))
          elif cos(x)<0 and sin(x)<0 then
              max(cos(x),sin(x))
          else 0
          end if:

b := plot(f, 0..4*Pi, filled=true, color=green):

plots:-display([sine, cosine, b, s, c]);

 

Download Heck_15.5.mw

If you click on the magenta error message as displayed in the Maple GUI (and if Maple is set to find your web-browser) then it should take you to this related Error Guide page.

[edit] On page 426 of the Heck text (as found by Google) I see the example in question as computing the problematic plot using the functional form, ie.
   b := plot(f, 0..4*Pi, filled=true, color=white):
in the 3rd edition (2003). That happens to coincide with the first way I gave above. It seems as if you have made a mistake, while editing his example.

Change

   Pi(d/2)

to,

   Pi*(d/2)

The former is a functional application of the name Pi to the argument d/2. Presumably you want the multiplication. instead.

In 2D Input you could also use a space before the bracket, to denote so-called implicit multiplication. I find that hard to distinguish, visually.

You can insert the explicit multiplication sign whether in 1D or 2D input mode, and I think doing so is a good idea.
 

restart;

V := (4*Pi(d/2)^3)/3;

(4/3)*Pi((1/2)*d)^3

eval(V, d = 6.35*mm);

(4/3)*Pi(3.175000000*mm)^3

lprint(indets(%,function));

{Pi(3.175000000*mm)}

V := (4*Pi*(d/2)^3)/3;

(1/6)*Pi*d^3

eval(V, d = 6.35*mm);

134.0663539*mm^3

V := 4*Pi*((1/2)*d)^3*(1/3)

(1/6)*Pi*d^3

eval(V, d = 6.35*mm)

134.0663539*mm^3

V := 4*Pi*((1/2)*d)^3*(1/3)

(1/6)*Pi*d^3

eval(V, d = 6.35*mm)

134.0663539*mm^3

 

Download multiplication_syntax.mw

It is documented in the Help page with topic coloncolon .

First 107 108 109 110 111 112 113 Last Page 109 of 336