PatrickT

Dr. Patrick T

2088 Reputation

18 Badges

14 years, 87 days

MaplePrimes Activity


These are replies submitted by PatrickT

Stating the obvious:

Given the problem's symmetry, once you have 1 solution, you have 4*3*2=24 solutions.

Kitonum, on my system your loop took several minutes (Maple 15 Windows7x64).

To get data about how long, I rewrote wrapped your code into a procedure:



SolveIt := proc(v::realcons:=7.11,r::range:=0.7..7.11/4,s::realcons:=0.01)
  local a,b,c,d,R,delta,r1,r2;
  r1:=lhs(r):
  r2:=rhs(r):
  R:=[infinity,[]]:
  for a from r1 by s to r2 do 
    for b from a by s to (v-a)/3 do 
      for c from b by s to (v-a-b)/2 do 
        for d from c by s to min(3.2,v-a-b-c) do 
        delta:=(v-(a+b+c+d))^2+(v-a*b*c*d)^2; 
        if delta<s and delta<R[1] then R:=[delta,[a,b,c,d]]: end if: 
        end do: 
      end do: 
    end do: 
   end do:
   return R;
end proc:

CodeTools:-Usage(SolveIt());
memory used=25.43GiB, alloc change=0 bytes, cpu time=18.69m, real time=19.85m
 [0., [1.20, 1.25, 1.50, 3.16]]

 

So it took about 20 minutes. 

Unfortunately, I'm not competent to make it more efficient.

Note that the procedure above is a little more general in that you can modify the range over which to search (default=0.7..7.11/4) or play around with other values of the sum/product (default=7.11) or of the precision required (default=0.01)

Example: SolveIt(v=7.11,r=1.19..3.17,s=0.01); 

As far as I can tell, your loop rules out multiplicities, i.e. cases where a=b, but it's probably easy to change that by starting the do loops from a-0.01 instead of a, etc.  I think.

Stating the obvious:

Given the problem's symmetry, once you have 1 solution, you have 4*3*2=24 solutions.

Kitonum, on my system your loop took several minutes (Maple 15 Windows7x64).

To get data about how long, I rewrote wrapped your code into a procedure:



SolveIt := proc(v::realcons:=7.11,r::range:=0.7..7.11/4,s::realcons:=0.01)
  local a,b,c,d,R,delta,r1,r2;
  r1:=lhs(r):
  r2:=rhs(r):
  R:=[infinity,[]]:
  for a from r1 by s to r2 do 
    for b from a by s to (v-a)/3 do 
      for c from b by s to (v-a-b)/2 do 
        for d from c by s to min(3.2,v-a-b-c) do 
        delta:=(v-(a+b+c+d))^2+(v-a*b*c*d)^2; 
        if delta<s and delta<R[1] then R:=[delta,[a,b,c,d]]: end if: 
        end do: 
      end do: 
    end do: 
   end do:
   return R;
end proc:

CodeTools:-Usage(SolveIt());
memory used=25.43GiB, alloc change=0 bytes, cpu time=18.69m, real time=19.85m
 [0., [1.20, 1.25, 1.50, 3.16]]

 

So it took about 20 minutes. 

Unfortunately, I'm not competent to make it more efficient.

Note that the procedure above is a little more general in that you can modify the range over which to search (default=0.7..7.11/4) or play around with other values of the sum/product (default=7.11) or of the precision required (default=0.01)

Example: SolveIt(v=7.11,r=1.19..3.17,s=0.01); 

As far as I can tell, your loop rules out multiplicities, i.e. cases where a=b, but it's probably easy to change that by starting the do loops from a-0.01 instead of a, etc.  I think.

@Preben Alsholm That's a very nice worksheet, thanks for sharing.

@Preben Alsholm That's a very nice worksheet, thanks for sharing.

you'll get more help if you can state your question more clearly and at least write the first few steps. From what you've said, it sounds like 2 equations and 4 unknowns.

 

@Mac Dude 

Like Alejandro, Preben and probably most people, I too am not keen on having to retype complicated expressions. To get the expression in a mapleprimes-friendly notation, I find that lprint usually works well.

ex:=(-14+9*(2-2*cos(mux))^(1/2))*cos(mu*x)+62+27*(2-2*cos(mux))^(1/2);
lprint(%);
 
(-14+9*(2-2*cos(mux))^(1/2))*cos(mu*x)+62+27*(2-2*cos(mux))^(1/2)

 

 

 

 

 

 

 

Can you give an example of the expression you want to collect?

I gave it a quick try and got this:

restart;
expr := x^(1/2)+ (2/x+x)*x^(1/2):
factor(expr,sqrt(x)); # with factor

(x+2+x^2)/x^(1/2)

collect(expr,sqrt(x)); # with collect

x^(3/2)+x^(1/2)+2/x^(1/2)

Even better! I'll try to remember to use this when Maple complains about complex values:

evalc(Re(a+I*b)) = a

 

Even better! I'll try to remember to use this when Maple complains about complex values:

evalc(Re(a+I*b)) = a

 

 As John says, you'll get more help if you show the exact problem. If it is derived from prior computation, just copy the final equations/sets.

Also check this recent exchange, for possible hints:

http://www.mapleprimes.com/questions/141258-The-Catcher-In-The-Rye

 

 

 

@Preben Alsholm 

seq( Q(b,Lambda), params = [b=1,Lambda=1] ) ;

is what I intended to write, thanks, for some reason the sillier the mistake the less I see it!

P.S. I sort of remember a little more about it now, I was experimenting with declaring params as a 'parameter' of dsolve, was running out of battery on my laptop, had to rush, something like that ... apologies for adding to "noise"

 

 

 

 

 

 

 

@Preben Alsholm 

seq( Q(b,Lambda), params = [b=1,Lambda=1] ) ;

is what I intended to write, thanks, for some reason the sillier the mistake the less I see it!

P.S. I sort of remember a little more about it now, I was experimenting with declaring params as a 'parameter' of dsolve, was running out of battery on my laptop, had to rush, something like that ... apologies for adding to "noise"

 

 

 

 

 

 

 

I guess I had in mind the below-average student after all (someone like me).

However straightforward Markiyan's suggestion may be, it does involve knowing about the DirectSearch optimization package, which doesn't come in bundled with Maple. I didn't know about it until I read this exchange. 

And it does require a proper tweaking of the options (on selecting options, see also the exchange Markiyan links to)

Now perhaps we cannot expect Maple to find the optimum "out of the box", perhaps it is a "tricky" problem. It just doesn't look all that hard, but what do I know!

At any rate, every one of the suggestions here have been very useful to me, and no doubt others. So thanks to all.

Here is the link to version 2 of the package, written by Sergey Moiseev (I'm assuming this is the latest, dated February 2011).

http://www.maplesoft.com/applications/view.aspx?SID=101333

Edit: and this, by the way, is what I found the most intuitive approach:

plot3d( Re( sqrt((x-1)*(y-x))+sqrt((7-y)*(1-x))+sqrt((x-y)*(y-7)) )
    , x = 1 .. 7, y = 1 .. 7, 'color' = blue, 'axes' = box );

 

 

 

 

 

I guess I had in mind the below-average student after all (someone like me).

However straightforward Markiyan's suggestion may be, it does involve knowing about the DirectSearch optimization package, which doesn't come in bundled with Maple. I didn't know about it until I read this exchange. 

And it does require a proper tweaking of the options (on selecting options, see also the exchange Markiyan links to)

Now perhaps we cannot expect Maple to find the optimum "out of the box", perhaps it is a "tricky" problem. It just doesn't look all that hard, but what do I know!

At any rate, every one of the suggestions here have been very useful to me, and no doubt others. So thanks to all.

Here is the link to version 2 of the package, written by Sergey Moiseev (I'm assuming this is the latest, dated February 2011).

http://www.maplesoft.com/applications/view.aspx?SID=101333

Edit: and this, by the way, is what I found the most intuitive approach:

plot3d( Re( sqrt((x-1)*(y-x))+sqrt((7-y)*(1-x))+sqrt((x-y)*(y-7)) )
    , x = 1 .. 7, y = 1 .. 7, 'color' = blue, 'axes' = box );

 

 

 

 

 

I've only looked at this very briefly as I couldn't quite understand the question, but for whatever it's worth: 


ode1:=diff(f(eta),eta$3)+f(eta)*diff(f(eta),eta$2)-diff(f(eta),eta$1)^2-M^2*diff(f(eta),eta$1)+M^2*b+b^2=0:
ode2:=diff(g(eta),eta$3)+f(eta)*diff(g(eta),eta$2)+(Lambda-2*diff(f(eta),eta$1)-M^2)*diff(g(eta),eta$1)+diff(f(eta),eta$2)*g(eta)=0:
odesys := [ode1,ode2]:
bc := [ f(0) = 0, D(f)(0) = 1, D(f)(N) = b, g(0) = 0, D(g)(0) = 0, D(g)(N) = 0 ];
sys := [op(odesys),op(bc)];
values := [N=10,M=0.1];
params := [b,Lambda];
eval(sys,values);
sysf := eval(eval(sys,values),[b=1,Lambda=1]);
dsolve(sysf,'numeric');

[ seq( dsolve(eval(sys,values),'numeric','output'=listprocedure), params = [b=1,Lambda=1] ) ];
Error, (in dsolve/numeric/bvp/convertsys) too few boundary conditions: expected 8, got 6 

 

 


 

 

First 6 7 8 9 10 11 12 Last Page 8 of 93