Preben Alsholm

13703 Reputation

22 Badges

20 years, 113 days

MaplePrimes Activity


These are replies submitted by Preben Alsholm

@erik10 An option to plot, something like 'includeaxis1' ::truefalse with default false.
To show that it should be possible I played a little below.
I prefer Optimization:-Maximize and Minimize to maximize and minimize. The former are more reliable.

restart;
P:=%plot(10 + sin(x), x=3*Pi..4*Pi,view=_VW);
f,r:=op(1..2,P);
VW:=min(0,Optimization:-Minimize(f,r)[1])..max(0,Optimization:-Maximize(f,r)[1]);
value(subs(_VW=VW,P));
############
P:=%plot(-10 + sin(x), x=3*Pi..4*Pi,view=_VW);
f,r:=op(1..2,P);
VW:=min(0,Optimization:-Minimize(f,r)[1])..max(0,Optimization:-Maximize(f,r)[1]);
value(subs(_VW=VW,P));
############################
P:=%plot(sin(x), x=3*Pi..4*Pi,view=_VW);
f,r:=op(1..2,P);
VW:=min(0,Optimization:-Minimize(f,r)[1])..max(0,Optimization:-Maximize(f,r)[1]);
value(subs(_VW=VW,P));

This is basically just for fun and certainly not a workaround.
 

@ Thanks, I get your point.
 

Int(exp(I*m*theta)*exp(-I*n*theta),theta=0..2*Pi)/(2*Pi);
F:=factor(combine(%));

value(F) assuming m=n; # 1
value(F) assuming posint; # 0,  The generic case

 

@Ronan Notice the underscore before rest. That is a clear signal that it means something to Maple.
 

p:=proc(x::algebraic) [x,_rest] end proc;
p(2);
p(2,4,fff=87);

Inside the procedure it stands for possible extra input to p that is not mentioned as a parameter in p.

We can define the otherwise neutral operator &sublist as an actual operator:
 

`&sublist` := proc(N::list,lis::list) 
    local find_element:=
     proc(e,L::list)
       local idx:=ListTools:-Search(e,L);
       if idx=0 then
         return [];
       elif idx=numelems(L) then
         return [L[idx]];
       else
         return L[idx+1..-1]
       end if
     end proc;
     local final_result::truefalse:=true;
     local item,r::list:=lis;
     for item in N do 
       r:=find_element(item,r);
       if numelems(r)=0 then
         final_result:=false;
         break;
       end if;
      end do;
   final_result;
end proc:

Then examples:
 

[7,2,4] &sublist [2,6,5,7,3,2,9,4];
[7,2,4] &sublist [2,6,5,7,3,2,9,4];
[7,2,4] &sublist [2,1,4,2,6,7,3,9];
[7,2,4] &sublist [7,4,2,7,2,4];
[7,2,4] &sublist [7,7,7,7,2,2,2,7,4];

 

@Kitonum Using nm's code I tried overloading subset to deal with this concept of sublist.
The idea is taking from the help page for overload. See the example "SetOperations".
 

ListOperations := module() option package;  export `subset`; 
   local find_element:=
     proc(e,L::list)
       local idx:=ListTools:-Search(e,L);
       if idx=0 then
         return [];
       elif idx=numelems(L) then
         return [L[idx]];
       else
         return L[idx+1..-1]
       end if
     end proc;
#########
    `subset` := proc(N::list,lis::list) option overload;
        local final_result::truefalse:=true;
        local item,r::list:=lis;
     for item in N do 
       r:=find_element(item,r);
       if numelems(r)=0 then
         final_result:=false;
         break;
       end if;
   end do;
   final_result;
end proc:
end module:

Here are examples:
 

with(ListOperations);
[7,2,4] subset [2,6,5,7,3,2,9,4];
[7,2,4] subset [2,1,4,2,6,7,3,9];
[7,2,4] subset [7,4,2,7,2,4];
[7,2,4] subset [7,7,7,7,2,2,2,7,4];
################## Now actual sets:
{7,2,4} subset {2,6,5,7,3,2,9,4};
{7,2,4} subset {2,1,4,2,6,7,3,9};
{7,2,4} subset {7,4,2,7,2,4};
{7,2,4} subset {7,7,7,7,2,2,2,7,4};
{a,b,c} subset {d,e,f,t};
{a,b,c} subset {d,e,b,f,c,t,a};

 

It is quite noticeable.

@mmcdara Yes, I do that routinely.
E.g. in a procedure using results from a dsolve/numeric/parameters defined outside the procedure.
 

Note 3 to my answer:
You can handle 0.005..0.995 if you split it:
 

res1:=evalf(Int(z(q1, q2), q1=0.1..0.9, q2=0.1..0.9));
  res2:=evalf(Int(z(q1, q2), q1=0.005...0.1, q2=0.005...0.1))+
        evalf(Int(z(q1, q2), q1=0.9...0.995, q2=0.9...0.995));
   res1+res2

J2() returns 1.742509218.

@mmcdara Thanks for clarifying the situation!

You are posting an image. That would require any responder to type those 6 equations himself.
Give us text we can copy and paste into Maple.
The syntax doesn't have to be perfect. I see one syntax error right away: You cannot use square brackets as if they were parentheses.

@Kitonum and MB86.

Using Kitonum's code I tried this:
 

restart;

sys_ode := diff(x(t), t) = -x(t)^2/(4*Pi*y(t)*(x(t)^2 + y(t)^2)), diff(y(t), t) = y(t)^2/(4*Pi*x(t)*(x(t)^2 + y(t)^2));
ics := x(0) = 1, y(0) = 1:

ode1,ode2:=sys_ode;
ode2/ode1;
ode:=diff(y(x),x)=-(y(x)/x)^3;
dsolve(ode);
sol:=dsolve({ode,y(1)=1});
plot(rhs(sol),x=1/sqrt(2)..5,y=0..3,color=red); p1:=%: #Saving the plot

Sol := dsolve({sys_ode, ics}, {x(t),y(t)}, numeric);

plots:-odeplot(Sol,[x(t),y(t)], t=-45..45, color=blue,view=0..3);  p2:=%: # Saving the plot
plots:-display(p1,p2); # blue
plots:-display(p2,p1); #red except at the end
plots:-display(Array([p1,p2]));

If you use this events version you make sure that x(t) stops at 5.
 

Sol := dsolve({sys_ode, ics}, {x(t),y(t)}, numeric,events=[[x(t)=5,halt]]);

 

@Carl Love Thanks Carl.
Two comments:
1.
I was just now looking at the help page for type/satisfies. It says:

"Predicates are expected to return normally, without raising exceptions."
My predicates don't meet that condition.

2.

The example of the use of overload(callseq_only) in the help page for overload is AppendUnique, which has nothing to do with jumping from procedure 1 to procedure 2 as the statement in help page talks about.

 

@Carl Love Thanks for commenting on this.

Here is the example:
overload_callseq_only_2.mw

@Ronan I have submitted an SCR about option overload(callseq_only).
I made an admittedly contrived example, where an exception (i.e. error) is raised in the parameter checking phase.
The execution didn't proceed from p1 to p2.

@Ronan I'm beginning to see that your original foo1 is behaving correctly, though not as you intended:
 

restart;
foo1:=overload([                        
                  proc(P1::list,P2::list,P3::list,$)
                     option overload;
                     print("3 lists");
                  end proc,

                  proc(P1::list,P2::list,a::algebraic:=4,$)
                     option overload;
                     print("2 lists");
                  end proc
                       ]):
foo1([1,2],[3,4]); #Output correct because P1 and P2 are lists
foo1([1,2],[3,4],4); 
foo1([1,2],[3,4],[4,7]);

Now, however, I don't see any need for using option overload(callseq_only).
I have been looking for examples in the documentation, but have not found any.

@Ronan Yes your example foo3 is puzzling.

Contrast the example with this:

p1:=proc(P1::list,P2::list,P3::list,$)
          P3
end proc;
#######     

p1([1,2],[3,4]); # Error message

But if the body of the procedure p1 doesn't make use of P3 there will be no error.

foo3 didn't produce an error message, it just jumped to the second procedure.

5 6 7 8 9 10 11 Last Page 7 of 229