Kitonum

16053 Reputation

24 Badges

12 years, 198 days

MaplePrimes Activity


These are answers submitted by Kitonum

Use additional graphic options that can significantly improve the quality of plotting. The plot size can be changed with  size  option, and the style (including size) of the legends is controlled by  legendstyle  option. As an example, look at the plotting 4 basic trigonometric functions on one plot by default and using additional options:


 

restart;
# By default
plot([sin(x),cos(x),tan(x),cot(x)], x=-2*Pi..2*Pi, y=-4..4, legend=[sin(x),cos(x),tan(x),cot(x)], scaling=constrained);

 

# With additional options
plot([sin(x),cos(x),tan(x),cot(x),seq([-2*Pi+Pi/2*k,t,t=-4..4],k=0..8)], x=-2*Pi..2*Pi, y=-4..4, legend=[sin(x),cos(x),tan(x),cot(x),"vertical asymptotes"$9], linestyle=[1$4,3$9], legendstyle=[font=[times,18]], color=[red,blue,green,gold, black$9], thickness=[2$4,0$9], discont, scaling=constrained, size=[900,600]);

 

 


Additionally, I replaced the vertical lines that Maple draws by default at break points with vertical dashed black lines and indicated them in the legends. The colors of the graphs have also been changed.

Download options.mw

I did not find a command in Maple for expanding a function into a Fourier series. But here's a simple procedure that does it for a function on the segment  -Pi .. Pi . I leave it to you as a simple exercise to modify it for a function given on an arbitrary segment.
 

restart;
Fourier:=proc(f::algebraic,N::nonnegint)
local a,b,k;
a:=k->`if`(k=0,1/(2*Pi)*int(f,x=-Pi..Pi),(1/Pi)*int(f*cos(k*x),x=-Pi..Pi));
assume(n,nonnegint);
print('a'[0]=a(0), 'a'[n]=a(n));
b:=k->(1/Pi)*int(f*sin(k*x),x=-Pi..Pi);
print('b'[n]=b(n));

a(0)+add(a(k)*cos(k*x)+b(k)*sin(k*x),k=1..N);

end proc:

# Example of use

Fourier(abs(x), 5);
plot([abs(x),%], x=-Pi..Pi, color=[blue,red], size=[800,400], scaling=constrained);

a[0] = (1/2)*Pi, a[n] = 2*((-1)^n-1)/(Pi*n^2)

 

b[n] = 0

 

(1/2)*Pi-4*cos(x)/Pi-(4/9)*cos(3*x)/Pi-(4/25)*cos(5*x)/Pi

 

 

 


Edit.

Download Fourier_series1.mw

Here's another easy way. Thу  ZigZag  procedure arranges the matrix indices in zigzag order. The matrix can be arbitrary (not necessarily square).

restart;

ZigZag:=proc(M,N)
local L, P;
uses ListTools;
L:=[seq(seq([i,j],i=1..M),j=1..N)];
P:=[ListTools:-Categorize((x,y)->x[1]+x[2]=y[1]+y[2], L)];
[seq(`if`(k::odd,op(P[k]),op(Reverse(P[k]))),k=1..M+N-1)];
end proc:


Examples of use

ZigZag(3,3);

[[1, 1], [1, 2], [2, 1], [3, 1], [2, 2], [1, 3], [2, 3], [3, 2], [3, 3]]

(1)

Matrix(4,6,{seq((op(ZigZag(4,6)[k]))=k,k=1..4*6)});

Matrix(4, 6, {(1, 1) = 1, (1, 2) = 2, (1, 3) = 6, (1, 4) = 7, (1, 5) = 14, (1, 6) = 15, (2, 1) = 3, (2, 2) = 5, (2, 3) = 8, (2, 4) = 13, (2, 5) = 16, (2, 6) = 21, (3, 1) = 4, (3, 2) = 9, (3, 3) = 12, (3, 4) = 17, (3, 5) = 20, (3, 6) = 22, (4, 1) = 10, (4, 2) = 11, (4, 3) = 18, (4, 4) = 19, (4, 5) = 23, (4, 6) = 24})

(2)

 


 

Download ZigZag.mw

See the  Large Operators  palette :

                               

 

In Maple we can use the  extrema  command for symbolic calculation of the  maximum  or the  minimum . The  extrema  command employs the method of Lagrange multipliers. Of course, this method is not universal and can fail if the extremum is reached at the points where differentiability is violated.

 

restart:
f:=(x-2*y)/(5*x^2-2*x*y+2*y^2):
V:=extrema(f, {2*x^2 - y^2 + x*y=1}, {x,y}, s);
s;
s1:=convert(s,list);
simplify(eval~(f, s1)); # Check

{-(1/4)*2^(1/2), (1/4)*2^(1/2)}

 

{{x = -(1/3)*6^(1/2), y = -(1/6)*6^(1/2)-(1/2)*2^(1/2)}, {x = -(1/3)*6^(1/2), y = -(1/6)*6^(1/2)+(1/2)*2^(1/2)}, {x = (1/3)*6^(1/2), y = (1/6)*6^(1/2)-(1/2)*2^(1/2)}, {x = (1/3)*6^(1/2), y = (1/6)*6^(1/2)+(1/2)*2^(1/2)}}

 

[{x = -(1/3)*6^(1/2), y = -(1/6)*6^(1/2)-(1/2)*2^(1/2)}, {x = -(1/3)*6^(1/2), y = -(1/6)*6^(1/2)+(1/2)*2^(1/2)}, {x = (1/3)*6^(1/2), y = (1/6)*6^(1/2)-(1/2)*2^(1/2)}, {x = (1/3)*6^(1/2), y = (1/6)*6^(1/2)+(1/2)*2^(1/2)}]

 

[(1/4)*2^(1/2), -(1/4)*2^(1/2), (1/4)*2^(1/2), -(1/4)*2^(1/2)]

(1)

 


We see that the maximum  sqrt(2)/4  is reached at two points. At the same time, we also learned everything about the minimum.

 

Download extrema.mw

1. For grouping the terms of an equation in Maple do not use square or curly brackets (only parentheses).

2. There is no need to use the  fsolve  command first for plotting, you can immediately plot with the  plots:-implicitplot  command. We see 2 values of  M  for each value of  sigmai from the range  0.1..0.4 :


 

Eq:=-(1/18)*(((M+sqrt(3)*sqrt(sigmai))^2-(M-sqrt(3)*sqrt(sigmai))^2)^(3/2)-(M+sqrt(3)*sqrt(sigmai))^3+(M-sqrt(3)*sqrt(sigmai))^3)*sqrt(3)/sqrt(sigmai)+2*f*(1-(1+(1/2*(qc-1))*(M-sqrt(3)*sqrt(sigmai))^2)^((3*qc-1)/(2*qc-2)))/(3*qc-1)+(2*(1-f))*(1-(1+(1/2)*beta*(qh-1)*(M-sqrt(3)*sqrt(sigmai))^2)^((3*qh-1)/(2*qh-2)))/(beta*(3*qh-1))=0;
params:=[qc=0.7,qh=0.7,beta=0.1, f=0.11];
R:=sigmai=0.1..0.4;
Eq1:=eval(Eq, params);
plots:-implicitplot(Eq1, R, M=-10..10, gridrefine=4);

-(1/18)*(((M+3^(1/2)*sigmai^(1/2))^2-(M-3^(1/2)*sigmai^(1/2))^2)^(3/2)-(M+3^(1/2)*sigmai^(1/2))^3+(M-3^(1/2)*sigmai^(1/2))^3)*3^(1/2)/sigmai^(1/2)+2*f*(1-(1+(1/2)*(qc-1)*(M-3^(1/2)*sigmai^(1/2))^2)^((3*qc-1)/(2*qc-2)))/(3*qc-1)+2*(1-f)*(1-(1+(1/2)*beta*(qh-1)*(M-3^(1/2)*sigmai^(1/2))^2)^((3*qh-1)/(2*qh-2)))/(beta*(3*qh-1)) = 0

 

[qc = .7, qh = .7, beta = .1, f = .11]

 

sigmai = .1 .. .4

 

-(1/18)*(((M+3^(1/2)*sigmai^(1/2))^2-(M-3^(1/2)*sigmai^(1/2))^2)^(3/2)-(M+3^(1/2)*sigmai^(1/2))^3+(M-3^(1/2)*sigmai^(1/2))^3)*3^(1/2)/sigmai^(1/2)+16.38181818-.2000000000/(1-.1500000000*(M-3^(1/2)*sigmai^(1/2))^2)^1.833333333-16.18181818/(1-0.1500000000e-1*(M-3^(1/2)*sigmai^(1/2))^2)^1.833333333 = 0

 

 

``


 

Download eq_new.mw

 

We can think of a conformal mapping as a mapping from R^2 to R^2 :


 

restart;
assume(y, real);
assume(x, real);
f := z -> I + z*exp(1/4*I*Pi);
w := f(x + y*I);
u := Re(w);
v := Im(w);
with(plots): with(plottools):
R:=display(polygon([[0,0],[1,0],[0,1]],color="LightBlue"),seq(plot(i,x=0..1-i,color=black),i=0..1,0.1),plot([seq([i,t,t=0..1-i],i=0..1,0.1)],color=black)):
F:=transform(unapply([u,v],x,y)):
`f(R)`:=display(F(R)):
display(<R |`f(R)`>, scaling=constrained, size=[300,300]);
display(R,`f(R)`);

proc (z) options operator, arrow; I+z*exp(((1/4)*I)*Pi) end proc

 

I+(x+I*y)*((1/2)*2^(1/2)+((1/2)*I)*2^(1/2))

 

(1/2)*x*2^(1/2)-(1/2)*y*2^(1/2)

 

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

 

 

 

 

 

 

 

 

 


 

Download conf.mw


 

restart; with(plots); with(plots, implicitplot)

pm2 := .5; dm2 := .14

NULL

A := inequal({pm2 > dm2+am2}, dt = 0 .. 1, am2 = 0 .. 1, color = "SkyBlue", numpoints = 8000); B := textplot([seq(seq([x, y, "+"], y = 0.3e-1 .. .33, 0.75e-1), x = 0.3e-1 .. .97, 0.47e-1)], font = [times, bold, 14]); display(A, B)

 

NULL


 

Download inequal_question_new.mw

restart;
eq:=x^2+2*x-1=0;
x=~[solve(eq)];

                   

 

Let  be the number of points on one dice, and   b  be the number of points on another one.
 

restart;
LE:=proc(a::integer,b::integer)
(type(a,even) and type(b,odd)) or (type(a,odd) and type(b,even)) implies a+b<=9;
end proc:

# Examples of use:
LE(2,3);
LE(5,6);

true

 

false

(1)

 


 

Download LE.mw

 

You can use an inert form for subtraction to keep the expression unchanged. For any calculations and transformations use the  value  command:

restart;
expr:=arccos(p%-a);
value(expr);
value(eval(expr,[p=0,a=1]));

                     

 

_B1  is a binary variable that is 0 or 1 :

restart;
ode:=diff(y(x),x)-y(x)/x+csc(y(x)/x)=0;
sol:=dsolve([ode,y(1)=0]);
about(_B1);
sol1:=eval(sol,_B1=0);
sol2:=eval(sol,_B1=1);
odetest(sol1,ode);
odetest(sol2,ode);

                   

Here is a solution in Maple:
 

restart;
Student:-Calculus1:-Roots(1/x^3-sin(12*x)=0, x=1.2..2);
map(x->[x,1/x^3], %); # Solutions of the system

Warning, some roots are returned as numeric approximations

 

[1.266058343, 1.591679997, 1.818677859]

 

[[1.266058343, .4927638521], [1.591679997, .2479891755], [1.818677859, .1662389018]]

(1)

 


 

Download nlsystem.mw

restart;
plots:-animate(plot,[cos(2*theta),theta=0..a, coords=polar], a=0..2*Pi);

 

First 13 14 15 16 17 18 19 Last Page 15 of 249