24 Badges

13 years, 70 days

LinearAlgebra:-Norm...

@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 .

Solution...

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);
 (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,pp1,piecewise(x>x2 and x
 (1)
 >

Download int1.mw

Edit.

Procedure...

 > restart; P:=proc() uses combinat; Matrix(2,3,randperm([\$1..6])); end proc:
 > # Examples seq(P(), i=1..10);
 (1)
 >

Download RM.mw

No generalization...

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]

Both solutions...

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)));
 (1)
 >

Download difeq1.mw

Edit.

eval...

 > 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);
 (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);
 (2)
 >

Download eval.mw

A way...

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

Edit.

Normalization...

Just normalize this vector.
An example:

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

Download RV.mw

minimize vs Optimization:-Minimize...

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});
 >

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.

evalc, convert(..., exp)...

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);
 (1)
 >

Download 111.mw

Or...

just shorter typing:

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

Bug...

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 sh...

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]);
 >

Download _piecewise.mw

Another way...

Example:

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

Finding y by x...

Since Maple does not explicitly solve your system of differential equations (only numerically), it is probably also impossible to express   in terms of  x  explicitly. But this is easy to do numerically. After that It's easy to plot the graph  y(x)  immediately using the numerical solution of the differential equation [x(t), y(t)]  as  parametric equations:

 > restart;         sys:=diff(x(t),t)=x(t)*y(t)+t,diff(y(t),t)=x(t)-t; diff(x(t), t) = x(t)*y(t)+t, diff(y(t), t) = x(t)-t; dsolve([sys,x(0)=0,y(0)=1],[x(t),y(t)]); # NULL (no answer from Maple)          sol:=dsolve([sys,x(0)=0,y(0)=1],[x(t),y(t)],numeric); # Examples X:=s->eval(x(t),sol(s)); Y:=s->eval(y(t),sol(s)); X(1); Y(2); plots:-odeplot(sol,[x(t),y(t)], t=0..2); # The plot y=F(x) plots:-odeplot(sol,[t,x(t)], t=0..2); plots:-odeplot(sol,[t,y(t)], t=0..2);
 > # Finding y numerically by x F:=x->Y(fsolve(s->X(s)-x, 0..infinity)); # Examples F(2), F(3); plot(F, 0..4, labels=["x","y"]); # The same plot as above
 >

Edit.

Download y_by_x1.mw

 First 17 18 19 20 21 22 23 Last Page 19 of 259
﻿