Kitonum

15509 Reputation

24 Badges

12 years, 137 days

MaplePrimes Activity


These are answers submitted by Kitonum

Maple finds both real and complex solutions. The  select  command helps to select real roots:
 

restart;

F := -1 - y - exp(x);
G := x^2 + y*(exp(x) - 1);
sol1 := solve({F, G}, {x, y});
sol2:=allvalues(sol1);
``;
select(p->type(eval(x,p),realcons) and type(eval(y,p),realcons),[sol2])[];

-1-y-exp(x)

 

x^2+y*(exp(x)-1)

 

{x = RootOf(-(exp(_Z))^2+_Z^2+1), y = -1-exp(RootOf(-(exp(_Z))^2+_Z^2+1))}

 

{x = 0, y = -2}, {x = RootOf(-(exp(_Z))^2+_Z^2+1, 0.8091750422e-1+1.468988335*I), y = -1-exp(RootOf(-(exp(_Z))^2+_Z^2+1, 0.8091750422e-1+1.468988335*I))}, {x = RootOf(-(exp(_Z))^2+_Z^2+1, 0.8091750422e-1-1.468988335*I), y = -1-exp(RootOf(-(exp(_Z))^2+_Z^2+1, 0.8091750422e-1-1.468988335*I))}

 

``

 

{x = 0, y = -2}

(1)

 


Edit. Of course, you can immediately get the solution (as float number) you want using  fsolve  command:

sol := fsolve({F, G}, {x, y});

                                       sol := {x = 0., y = -2.000000000}

 

Download solve.mw

@Zeineb  What you want to calculate is called a (matrix) norm. Carl showed one way (the  infinity-norm). But there are other formulas for calculating a norm, and Maple has a suitable command. See help on  ?LinearAlgebra:-Norm .

 

Obviously, the function  g  depends not only on x, but also on p , so  g(x,p)=max{h(x,p),f(x,p) . It is useful to use graphic illustration to obtain this dependence. First, we plot a red line  x-p=x^2+p*x . It is easy to check that above this line (pink area) we have  g(x,p)=x^2+p*x, and below (blue area)  g(x,p)=x-p


 

restart;
eq:=x-p=x^2+p*x;
f:=unapply(solve(eq, p), x);
P1:=plot(f, 0..10, p=-1..1, color=red, thickness=3):
P2:=plots:-inequal(p>f(x),x=0..10,p=-1..1,color="LightPink",optionsexcluded = [color = "LightBlue"],nolines):
T:=plots:-textplot([[5,0.3,g(x,p)=x^2+p*x],[1,-0.7,g(x,p)=x-p]], font=[times,bold,16]):
plots:-display(P1,P2,T, size=[800,400]);

g:=unapply(piecewise(p>=f(x),x^2+p*x,x-p), x,p);
Sol:=unapply(int(g(x,p), x=0..10), p);

# Examples of use
Sol(2), Sol(1), Sol(0), Sol(-2);

eq := x-p = p*x+x^2

 

f := proc (x) options operator, arrow; -x*(x-1)/(x+1) end proc

 

 

g := proc (x, p) options operator, arrow; piecewise(-x*(x-1)/(x+1) <= p, p*x+x^2, x-p) end proc

 

proc (p) options operator, arrow; 50*p-60*p*piecewise(-p < 90/11, 0, 1)+1000/3-(850/3)*piecewise(-p < 90/11, 0, 1)+piecewise(And(p <= 3-2*2^(1/2), 0 < p), (1/8)*piecewise(-signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)*p^2*(p^2-6*p+1)^(1/2)-(3/4)*piecewise(-signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)*p*(p^2-6*p+1)^(1/2)-(1/12)*piecewise(-signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)+(1/12)*piecewise(-signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)*p^3-(3/4)*piecewise(-signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)*p^2+(1/8)*piecewise(-signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)*(p^2-6*p+1)^(1/2)-(1/24)*piecewise(-signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)*(p^2-6*p+1)^(3/2)+(3/4)*piecewise(-signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)*p+(1/12)*piecewise(signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)+(3/4)*piecewise(signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)*p*(p^2-6*p+1)^(1/2)-(1/8)*piecewise(signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)*p^2*(p^2-6*p+1)^(1/2)+(3/4)*piecewise(signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)*p^2-(3/4)*piecewise(signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)*p-(1/8)*piecewise(signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)*(p^2-6*p+1)^(1/2)-(1/12)*piecewise(signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)*p^3+(1/24)*piecewise(signum((p^2-6*p+1)^(1/2)/(p-3+(p^2-6*p+1)^(1/2))) = 1, 1, 0)*(p^2-6*p+1)^(3/2), 0)+piecewise(And(p <= 3-2*2^(1/2), -90/11 < p), (1/12)*piecewise(-signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)*p^3-(3/4)*piecewise(-signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)*p^2-(1/8)*piecewise(-signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)*(p^2-6*p+1)^(1/2)+(1/24)*piecewise(-signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)*(p^2-6*p+1)^(3/2)+(3/4)*piecewise(-signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)*p-(1/8)*piecewise(-signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)*p^2*(p^2-6*p+1)^(1/2)+(3/4)*piecewise(-signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)*p*(p^2-6*p+1)^(1/2)+(1/8)*piecewise(signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)*p^2*(p^2-6*p+1)^(1/2)-(3/4)*piecewise(signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)*p*(p^2-6*p+1)^(1/2)-(1/12)*piecewise(signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)*p^3+(3/4)*piecewise(signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)*p^2+(1/8)*piecewise(signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)*(p^2-6*p+1)^(1/2)-(1/24)*piecewise(signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)*(p^2-6*p+1)^(3/2)-(3/4)*piecewise(signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)*p-(1/12)*piecewise(-signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0)+(1/12)*piecewise(signum((p^2-6*p+1)^(1/2)/(-p+(p^2-6*p+1)^(1/2)+3)) = 1, 1, 0), 0) end proc

 

1300/3, 1150/3, 667/2, 2863/12+(17/12)*17^(1/2)

(1)

 


 

Download int.mw


Here's another solution that is slightly more cumbersome but gives more compact results:


 

restart;
eq:=x-p=x^2+p*x;
f:=unapply(solve(eq, p), x);
plot(f, 0..10, p=-1..1);
maximize(f(x), x=0..10, location);
M:=expand~([%])[];
p1:=f(0); p2:=M[1];
x1,x2:=solve(eq, x);
g:=unapply(piecewise(p>=p2,x^2+p*x,p<p2 and p>p1,piecewise(x>x2 and x<x1,x-p,x^2+p*x),p<=p1,piecewise(x<=x1,x-p,x^2+p*x)), x,p);
Sol:=unapply(simplify(int(g(x,p), x=0..10)), p);

# Examples of use
Sol(2), Sol(1), Sol(0), Sol(-2);
 

eq := x-p = p*x+x^2

 

f := proc (x) options operator, arrow; -x*(x-1)/(x+1) end proc

 

 

-(1/2)*(sqrt(2)-1)*(sqrt(2)-2)*sqrt(2), {[{x = sqrt(2)-1}, -(1/2)*(sqrt(2)-1)*(sqrt(2)-2)*sqrt(2)]}

 

M := -2*sqrt(2)+3, {[{x = sqrt(2)-1}, -2*sqrt(2)+3]}

 

p1 := 0

 

p2 := -2*sqrt(2)+3

 

x1, x2 := -(1/2)*p+1/2+(1/2)*sqrt(p^2-6*p+1), -(1/2)*p+1/2-(1/2)*sqrt(p^2-6*p+1)

 

g := proc (x, p) options operator, arrow; piecewise(-2*sqrt(2)+3 <= p, p*x+x^2, 0 < p and p < -2*sqrt(2)+3, piecewise(-(1/2)*p+1/2-(1/2)*sqrt(p^2-6*p+1) < x and x < -(1/2)*p+1/2+(1/2)*sqrt(p^2-6*p+1), x-p, p*x+x^2), p <= 0, piecewise(x <= -(1/2)*p+1/2+(1/2)*sqrt(p^2-6*p+1), x-p, p*x+x^2)) end proc

 

proc (p) options operator, arrow; piecewise(p < -90/11, 50-10*p, p <= 0, (1/12)*(p^2-6*p+1)^(3/2)-(1/12)*p^3+(3/4)*p^2+(197/4)*p+4001/12, p < -2*2^(1/2)+3, (1/6)*(p^2-6*p+1)^(3/2)+50*p+1000/3, -2*2^(1/2)+3 <= p, 50*p+1000/3) end proc

 

1300/3, 1150/3, 667/2, (17/12)*17^(1/2)+2863/12

(1)

 


 

Download int1.mw

Edit.


 

restart;
P:=proc()
uses combinat;
Matrix(2,3,randperm([$1..6]));
end proc:

# Examples
seq(P(), i=1..10);

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

(1)

 


 

Download RM.mw

algsubs is not a generalization of  subs, at least because  subs  allows multiple substitutions to be made at once, which  algsubs  does not:

restart:
subs([a=c,b=d],a=b);
algsubs([a=c,b=d],a=b);

                                                          c = d
     Error, invalid input: algsubs expects its 1st argument, p, to be of type algebraic = algebraic, but received [a = c, b = d]

We can easily get both solutions if we make the change  y(x)=Y(x)^2 . Then our original equation splits into two equations, the first equation gives the obvious zero solution, and the second equation gives  Y(x)=x , that is  y(x)=x^2 :


 

restart:
ode := diff(y(x),x)=2*sqrt(y(x));
Change:=y(x)=Y(x)^2;
eval(ode,Change);
simplify(%) assuming Y(x)>=0;
Ode:=factor((lhs-rhs)(%))/2;
ic:=Y(0)=0;
``;
sol1:=eval(Change,Y(x)=0);
sol2:=eval(Change,dsolve([op(2,Ode),ic],Y(x)));

diff(y(x), x) = 2*y(x)^(1/2)

 

y(x) = Y(x)^2

 

2*Y(x)*(diff(Y(x), x)) = 2*(Y(x)^2)^(1/2)

 

2*Y(x)*(diff(Y(x), x)) = 2*Y(x)

 

Y(x)*(diff(Y(x), x)-1)

 

Y(0) = 0

 

``

 

y(x) = 0

 

y(x) = x^2

(1)

 


 

Download difeq1.mw

Edit.


 

restart;

assume(0 < a, 0 < L, a < L);

M := piecewise(0 <= x and x < a, P*x*(L-a)/L, a <= x and x < L, P*a*(L-x)/L);
ode := diff(y(x), `$`(x, 2)) = M/(E*I__0);
ic := y(0) = 0, y(L) = 0;
sol := factor(dsolve([ode, ic], y(x))); assign(sol); y1 := y(x);

M := piecewise(0 <= x and x < a, P*x*(L-a)/L, a <= x and x < L, P*a*(L-x)/L)

 

ode := diff(y(x), x, x) = piecewise(0 <= x and x < a, P*x*(L-a)/L, a <= x and x < L, P*a*(L-x)/L)/(E*I__0)

 

ic := y(0) = 0, y(L) = 0

 

sol := y(x) = piecewise(x < 0, -P*a*(2*L-a)*(L-a)*x/(6*L*E*I__0), x < a, -P*x*(L-a)*(2*L*a-a^2-x^2)/(6*L*E*I__0), x < L, -P*a*(L-x)*(2*L*x-a^2-x^2)/(6*L*E*I__0), L <= x, -P*a*(L-a)*(L+a)*(L-x)/(6*L*E*I__0))

 

piecewise(x < 0, -(1/6)*P*a*(2*L-a)*(L-a)*x/(L*E*I__0), x < a, -(1/6)*P*x*(L-a)*(2*L*a-a^2-x^2)/(L*E*I__0), x < L, -(1/6)*P*a*(L-x)*(2*L*x-a^2-x^2)/(L*E*I__0), L <= x, -(1/6)*P*a*(L-a)*(L+a)*(L-x)/(L*E*I__0))

(1)

Y:=eval(y1, [a=1,L=2,E=3,I__0=4,P=5]);
plot(Y, x=0..3);
minimize(Y, x=0..3);
maximize(Y, x=0..3);

Y := piecewise(x < 0, -5*x*(1/48), x < 1, -5*x*(-x^2+3)*(1/144), x < 2, -(1/144)*(5*(2-x))*(-x^2+4*x-1), 2 <= x, -5/24+5*x*(1/48))

 

 

-5/72

 

5/48

(2)

 


 

Download eval.mw

restart;
n:=2:
plots:-animate(plots:-display@plottools:-sphere,[r], r=0..n, frames=100, axes=normal);

                     

Edit.

Just normalize this vector.
An example:

restart;
V := RandomTools:-Generate(('Vector[row]')(integer(range = -3 .. 10, exclude = {0}), 4));
V/add(V);

Vector[row](4, {(1) = 9, (2) = 3, (3) = 6, (4) = 9})

 

Vector[row](%id = 18446745446184201382)

(1)

 


 

Download RV.mw

Maple does not have MINIMIZE command, but there are minimize (and maximize) commands for symbolic optimization and  Optimization:-Minimize  (and Optimization:-Maximize) commands for numerical optimization. Below, using a simple example of a piecewise function, I checked how these commands work. We see that minimize and maximize commands almost successfully copes with two examples, only in the second example maximize does not find a specific value for the maximum point. Optimization:-Minimize and  Optimization:-Maximize  commands fail in all examples.


 

restart;         
f:=piecewise(x<=0 and x>=-2,1/2*sin(3*x),x<=2 and x>0,abs(x-1)-1, 0);        
plot(f, x=-2..2, scaling=constrained, size=[800,400]);
        
minimize(f, location);
maximize(f, location);

Optimization:-Minimize(f,{x>=-2,x<=2});
Optimization:-Maximize(f,{x>=-2,x<=2});
 

f := piecewise(-2 <= x and x <= 0, (1/2)*sin(3*x), 0 < x and x <= 2, abs(x-1)-1, 0)

 

 

-1, {[{x = 1}, -1]}

 

1/2, {[{x = (1/6)*Pi+(2/3)*Pi*_Z10}, 1/2]}

 

Error, (in Optimization:-NLPSolve) no improved point could be found

 

Error, (in Optimization:-NLPSolve) no improved point could be found

 

 


 

Download min1.mw

Perhaps the best option for you to use the  DirectSearch  package, which is not in Maple, but it can be downloaded freely from the Maple Application Center.

Edit.

The  simplify  command for this example  doesn't work in Maple 2018.

Another way:


 

restart;
expression := exp(-I/2*(-2*rho__m + Pi))*I;
simplify(expression);
evalc(%);
convert(%, exp);

I*exp(-((1/2)*I)*(-2*rho__m+Pi))

 

I*exp(-((1/2)*I)*(-2*rho__m+Pi))

 

cos(rho__m)+I*sin(rho__m)

 

exp(I*rho__m)

(1)

 


 

Download 111.mw

just shorter typing:

evalf(Int(cos(3+sin(x)), x = 0 .. 5));

Of course it's a bug. Here is a direct calculation of this integral in Cartesian coordinates:

z:=sqrt(1-x^2-y^2);
int((x^2 + y^2)*z*sqrt(1+diff(z,x)^2+diff(z,y)^2),[y=-sqrt(1-x^2)..sqrt(1-x^2), x=-1..1]);

                                 

 

 

Download bug.mw

We can simply use the empty circle to show that the line is interrupted at the point [0,0] :

 

restart;
delta := t -> piecewise(t=0, 1, 0);
Line:=plot(delta(t), t=-1..1, color=red, thickness=4):
Options:=style=point,color=red,symbolsize=15:
Point1:=plot([[0,0]],symbol=circle,Options):
Point2:=plot([[0,1]],symbol=solidcircle,Options):
plots:-display(Line,Point1,Point2, scaling=constrained, size=[800,400]);

delta := proc (t) options operator, arrow; piecewise(t = 0, 1, 0) end proc

 

 

 


 

Download _piecewise.mw

Example:

n:=3:
Matrix(2^n,n, combinat:-permute([0$n,1$n],n));

                                 

 

1 2 3 4 5 6 7 Last Page 1 of 242