Kitonum

21680 Reputation

26 Badges

17 years, 185 days

MaplePrimes Activity


These are replies submitted by Kitonum

@denkasyan In  PolyhedralSets  package, a body must be given by non-strict inequalities. But to build a body it does not matter. Maple simply draws the boundaries of this body as parts of the planes. In your example, the body will be part of the plane  y = -20 .

@denkasyan  You get the set  {x<0, y=-20, z<0}

You got some useful tips, but if you want more specific help, then you need to explain in what the essence of the problem is. And more: what do your functions B, P mean, what is loss and so on?

If I understand correctly,  until "any condition"  is equivalent to  if "any condition" then break fi , but slightly shorter. The latter variant I use very often.

@acer  This example shows the importance of visualization (a plot) in these methods. How else would we know a priori that the result

Optimization:-Maximize(f, x=0..2*Pi, method = branchandbound);


is incorrect?


If we want to solve purely programmatically (not looking at the plots), then probably the best method will be a standard approach using the first derivative:

f:=x->sin(3*x)-cos(7*x)+sin(17*x)+cos(20*x)-sin(67*x):
R:=[RootFinding:-Analytic(diff(f(x),x), x, re=0..2*Pi, im=-1..1)];
Min=min(f~(R)[], f(0), f(2*Pi));
Max=max(f~(R)[], f(0), f(2*Pi));

 

Unfortunately  method=branchandbound  option is not very reliable. The example below shows that both the minimum and maximum are found incorrectly, which is clearly shown by the graph:

f:=sin(3*x)-cos(7*x)+sin(17*x)+cos(20*x)-sin(67*x):
plot(f, x=0..2*Pi, size=[1000,500], numpoints=1000);
Optimization:-Maximize(f, x=0..2*Pi, method = branchandbound);
Optimization:-Minimize(f, x=0..2*Pi, method = branchandbound);


DirectSearch  package successfully copes with the problem:

DirectSearch:-GlobalOptima(f, [x=0..2*Pi]);
DirectSearch:-GlobalOptima(f, [x=0..2*Pi], maximize);
                            
 [-4.82606452700204, [x = 3.59004152503469], 191]
                              [3.40373784598079, [x = 4.94786409954761], 162]
 

                   
 

 

@Bilawal  See another way in my answer. 

@Mariusz Iwaniuk  The results for  x>Pi/2  are erroneous:

F:=simplify(unapply(int(sqrt(sin(x)), x=0..T), T)) assuming T>0, T<=Pi;
F(Pi/4), F(Pi/2), F(3*Pi/4), F(Pi): 
# Examples
evalf([%])[];
 

@nm  Sorry, I am wrong. I had in mind a syntax error for the numerical solution. I corrected the title.

@ahmeng  See help on  value(%)  and  emptysymbol(``)

@Lali_miani  In Maple, there is a rule: if at least one number is represented as a decimal fraction, for example  0.2  in your example, then Maple calculates the entire expression approximately (by default with 10 significant digits). If you want to have a symbolic representation, then instead of 0.2 you should write 1/5, that is  sin(1/5) . But then in the output Maple just writes the same thing, since sin(1/5)  can not be exactly written in a simpler form, for example, in radicals. But with this expression it is possible to work further, for example to calculate it approximately with some accuracy or to expand in a series, etc.

 

 

@Lali_miani  Unfortunately I'm not familiar with English-language books on Maple (English is not my native language). Maybe someone else will advise you a good book on Maple.

@Carl Love  But by this we have total 3 significant digits, rather than 3 digits after the decimal point:

interface(displayprecision= 3):
evalf(Pi);
                                                   
3.14
 

@vv  Thanks for this effective way (I did not know about it before). In addition to your answer here is a quote from the Help: "To compute  i^n mod m where  i  is an integer, it is undesirable to use this "obvious" syntax because the powering will be performed first over the integers (possibly resulting in a very large integer) before reduction modulo m. Rather, the inert operator  &^  should be used:  i &^ n mod m .  In the latter form, the powering will be performed intelligently by the mod operation. 

@Joe Riel  It's better. I'm used to using this syntax for lists, but for vectors it also works.

First 48 49 50 51 52 53 54 Last Page 50 of 133