Kitonum

21525 Reputation

26 Badges

17 years, 74 days

MaplePrimes Activity


These are answers submitted by Kitonum

In addition to the numerical optimization commands  Optimization:-Maximize  and  Optimization:-Minimize, Maple has symbolic optimization commands  maximize  and  minimize , but none of these commands work with functions containing parameters. The simple examples below illustrate this. Optimization:-Maximize  and  Optimization:-Minimize commands does not work with piecewise-functions, even if they do not contain parameters.


 

restart;

f:=piecewise(x<=0,0,x<=2,x*(2-x),x<=3,2*(x-2),x<=5,-2*(x-4),-2);

f := piecewise(x <= 0, 0, x <= 2, x*(2-x), x <= 3, 2*x-4, x <= 5, -2*x+8, -2)

(1)

plot(f, x=-1..6, thickness=2, scaling=constrained);

 

Optimization:-Minimize(f, x=0..6); # a bug
minimize(f, x=0..6); # OK
maximize(f, x=0..6); # OK

[HFloat(1.754980553175305e-8), [x = HFloat(1.9999999912250972)]]

 

-2

 

2

(2)

minimize(x^2+a*x+1, x=-infinity..infinity); # no answer
minimize(x^2+a*x+1, x=-1..1); # no answer
minimize(eval(x^2+a*x+1,a=1), x=-1..1); # OK for a specific parameter

minimize(a*x+x^2+1, x = -infinity .. infinity)

 

minimize(a*x+x^2+1, x = -1 .. 1)

 

3/4

(3)

 


 

Download optimization_examples.mw

Check if maximize  and  minimize commands will work with your function for specific parameter values. If so, you can write a procedure to calculate these, the parameters of this procedure will be the parameters of your function. This procedure will allow you to solve a variety of problems, for example, to plot graphs the dependence of the maximum and minimum on parameters.

 

Let  a  and  b  be the major and minor semiaxes of the ellipse, c - focal distance. From the condition  b=с  and the equality  a^2=b^2+c^2 , we easily get that  a=c*sqrt(2)  and the eccentricity  e=1/sqrt(2) .  By the condition b = c  the ellipse is determined up to similarity, the alpha angle does not change, therefore, in the calculations, we can assume that  c=1 .
Below  r1  and  r2  are the distances from a point  M(x,y)  on the ellipse to the ellipse foci.


 

restart;
a:=c*sqrt(2):
e:=c/a:
r1:=a+e*x: r2:=a-e*x: c:=1:
Eq:=(2*c)^2=r1^2+r2^2-2*r1*r2*cos(alpha); # The cosine rule

4 = ((1/2)*2^(1/2)*x+2^(1/2))^2+(-(1/2)*2^(1/2)*x+2^(1/2))^2-2*((1/2)*2^(1/2)*x+2^(1/2))*(-(1/2)*2^(1/2)*x+2^(1/2))*cos(alpha)

(1)

solve(Eq, alpha);

Pi-arccos(x^2/(x^2-4))

(2)

maximize(%, x=0..a, location);

(1/2)*Pi, {[{x = 0}, (1/2)*Pi]}

(3)

 


 

Download max_angle.mw

Use  op(eqs)  or  eqs[ ]  for this.

restart;
S:={a*x,b*x, c*(x+y)};
S1:=op~(S);
S1 minus {a,b,c};

                           

restart;
eq:=sqrt(y)=tanh(x);
eq^2;

                                         

 


 

restart;

PMSM_v_eq := V__alphabeta(t) = R__s * i__alphabeta(t) + L__s*diff(i__alphabeta(t), t) + diff(lambda__alphabeta(t), t);

V__alphabeta(t) = R__s*i__alphabeta(t)+L__s*(diff(i__alphabeta(t), t))+diff(lambda__alphabeta(t), t)

(1)

PMSM_flux_eq := diff(lambda__alphabeta(t),t)=solve(PMSM_v_eq, diff(lambda__alphabeta(t),t));

map(int,PMSM_flux_eq,t);
IntegrationTools:-Expand(%);
applyop(IntegrationTools:-Combine,2,%);

diff(lambda__alphabeta(t), t) = -L__s*(diff(i__alphabeta(t), t))-R__s*i__alphabeta(t)+V__alphabeta(t)

 

lambda__alphabeta(t) = int(-L__s*(diff(i__alphabeta(t), t))-R__s*i__alphabeta(t)+V__alphabeta(t), t)

 

lambda__alphabeta(t) = -L__s*i__alphabeta(t)-R__s*(int(i__alphabeta(t), t))+int(V__alphabeta(t), t)

 

lambda__alphabeta(t) = int(-R__s*i__alphabeta(t)+V__alphabeta(t), t)-L__s*i__alphabeta(t)

(2)

 


Edit.

Download PMSM_eq_new1.mw

 

In each specific example, the shortest way is probably to use the  subsop  command:

restart;	
sol:={v[1]=t,v[2]=3/2*t,v[3]=v[3]}:
subsop(3=(),sol);

 

R:=1.33*10^(-9)*C/m^2;
evalf[3](op(1,R)*``(`*`(op(2..3,R))));

                     

 

restart;
expr:=exp(x)^3*sin(x)+3/(exp(x)^n):
A:=exp(t::anything)^n::anything=exp(t*n):
applyrule([1/A,A], expr);

                                    

Edit.

restart;
a:= 456;
L:=convert(a,base,10);
Array([seq(L[i],i=-1..-nops(L),-1)]);
# Or shorter
Array(ListTools:-Reverse(L));

                          

Edit.

Use  LinearAlgebra:-Modular  subpackage to work with matrices on a specific finite field.

To generate all such matrices, read the thread  https://mapleprimes.com/questions/211872-Generate-Invertible-4x4-Matrices-Over-F2-

restart;
x, y := r*cos(t), r*sin(t):
plot3d([[x, y, r], [x, y, 0]], r= 0..1, t= 0..Pi, scaling= constrained);

 

Your equation contains several parameters in addition to variables  x  and  y . For Maple to accept this equation as an ellipse equation, conditions on the parameters are necessary. To get these conditions, we first select complete squares:

restart;
with(geometry):
eqell := expand((x+(1/2)*R1-(1/2)*R)^2/a^2+y^2/b^2-1);
A:=Student:-Precalculus:-CompleteSquare(eqell,x,y);
B, C := selectremove(t->has(t,x)or has(t,y), A);  
Eq:=subsindets(B,`^`,t->applyop(simplify,1,t))=simplify(-C); # Simplified ellipse equation
geometry:-ellipse(ell, Eq, [x, y]) assuming a>0, b>0, a>b; 
detail(ell);

 

Edit.

Download Ellipse1.mw

Use the appropriate options. An example:

restart;
plot([sin(x),cos(x)], x=0..2*Pi, color=[blue,red], style=point, symbol=[cross,diagonalcross], symbolsize=12, numpoints=50, adaptive=false, size=[800,400], scaling=constrained);

                 

See help on  ?plot,options
If you want to have a solid line as well, and not just some symbols, then use  style=pointline  option.

Remember that  e  is just a Maple symbol (not Euler's number e), and the exponential function  e^x  should be coded as  exp(x) .
First, we plot this function to ensure the existence and uniqueness of the root.
 

restart;

f:=x->(5-x)*exp(x)-5:
a := 4.:
b := 5.:
nStep := 5:
plot(f, 4..5);

for n from 1 to nStep do
c:=(a+b)/2;
if f(a)*f(c)<0 then b:=c else a:=c fi;
od;

fsolve(f, 4..5); # For comparison
 

 

4.500000000

 

4.750000000

 

4.875000000

 

4.937500000

 

4.968750000

 

4.965114232

(1)

 


 

Download bisect.mw

First 49 50 51 52 53 54 55 Last Page 51 of 290