nm

3646 Reputation

17 Badges

7 years, 362 days

MaplePrimes Activity


These are answers submitted by nm

There might be a build in function in Maple to do this. But you could always do

N:=10: #must be even integer
lst:=[seq([i,N-i],i=1..N/2)]

corrected to use evalhf instead of evalf (I am not able to delete this for some reason).

It is always best to provide an example when asking such questions to eliminate any misunderstanding.

You could try

r:=evalf(Pi); 
parse(sprintf("%.10f",r)); #truncate to whatever number of decimals

if this is not what you meant, someone please feel free to delete my answer. I am not able to delete it. 

Try it with Maple 2019 Physics 348


 

pde := diff(u(x, t), t) = k*diff(u(x, t), x, x);
bc := u(x, 0) = T, u(0, t) = a*t + b, u(L, t) = T;
pdsolve([pde, bc], u(x, t)) assuming (0 < k, 0 < L, 0 < a, 0 < b, 0 < T, 0 <= t, 0 <= x and x <= L);

diff(u(x, t), t) = k*(diff(diff(u(x, t), x), x))

u(x, 0) = T, u(0, t) = a*t+b, u(L, t) = T

u(x, t) = (1/6)*(6*(Sum(2*sin(n*Pi*x/L)*(Pi^2*k*(T-b)*n^2+L^2*a)*exp(-Pi^2*n^2*k*t/L^2)/(n^3*Pi^3*k), n = 1 .. infinity))*k*L+((6*a*t+6*b)*L+6*x*(-a*t+T-b))*k-2*a*x*(L-x)*(L-(1/2)*x))/(L*k)

 

 


 

Download A.mw

I removed bc[4] but the code run withour any error but no solution displayed

It works for me on Maple 2019:


 

restart;

pde := diff(f(x, y), x $ 2) + diff(f(x, y), y $ 2) = 0;
bc[1] := f(x, 0) = exp(-x);
bc[2] := D[1](f)(0, y) = 0;
bc[3] := D[2](f)(x, 1) = 0;
sys := [pde, bc[1], bc[2], bc[3]];
sol := pdsolve(sys, f(x, y))

diff(diff(f(x, y), x), x)+diff(diff(f(x, y), y), y) = 0

f(x, 0) = exp(-x)

(D[1](f))(0, y) = 0

(D[2](f))(x, 1) = 0

[diff(diff(f(x, y), x), x)+diff(diff(f(x, y), y), y) = 0, f(x, 0) = exp(-x), (D[1](f))(0, y) = 0, (D[2](f))(x, 1) = 0]

f(x, y) = Sum(8*sin((1/2)*(1+2*n)*Pi*y)*((n+1/2)*Pi*(2+(1+(n+1/2)*Pi)^2*_C5(n))*exp((1/2)*(1+2*n)*Pi*x)+(n+1/2)*Pi*_C5(n)*(1+(n+1/2)*Pi)*(-1+(n+1/2)*Pi)*exp(-(1/2)*(1+2*n)*Pi*x)+2*exp(-x))/((1+2*n)^3*Pi^3+2*Pi^2*(1+2*n)^2), n = 0 .. infinity)+exp(-x)

 


 

Download foo.mw

One way could be

unassign('f,x,y');
f:=(x,y)->arctan(x*y^2);
diff(f(x,y),x);
diff(f(x,y),y);

 

One way could be

A:=Matrix([[0,1,0,1],[-1,3,0,0],[0,0,1,0]]);
ArrayNumElems(A,'NonZero')

5

in Maple index starts from 1 not zero. Try

 

f := proc (x, w)
     local k;   
     sum(w[k]*x^k, k = 1 .. nops(w))
end proc;

f(2, [a, b, c]);

No error now

But should not the call be f(x, [a, b, c]) ? I do not know what you are passing 2 there.

one possiblity might be

 

restart;
f:=x->3*x^3-2*x^2+5*x-7;
limit( (f(x+h)-f(x))/h, h=0)

9*x^2 - 4*x + 5

diff(f(x),x)

9*x^2 - 4*x + 5

 

restart;

#note: no error checking is done. This assumes solution 
#exist and point are not colinear.

get_circle_equation:=proc(pt1,pt2,pt3,x,y)
 local q,p,r,res,eq,sol;
 res:=map(pt->(pt[1]-q)^2+(pt[2]-p)^2=r^2,[pt1,pt2,pt3]);
 sol:=solve(res,[q,p,r]);
 assign(sol);
 return (x-q)^2+(y-p)^2=r^2;
end proc:

pt1:=[1,2];pt2:=[-3,0];pt3:=[5,-4];
cir:=get_circle_equation(pt1,pt2,pt3,x,y);
plots:-implicitplot(cir,x=-10..19,y=-10..10)

 

I normally use unapply for these things as follows

aux := rsolve({y(0) = y0, y(n) = 4*y(n-1)*(1-y(n-1))}, y(n));
solucao := unapply(aux,n,y0);
solucao(3,1/2);

 

 

I can't reproduce this on 2018.2.1 on windows

restart;
with(LinearAlgebra):
switch:=proc(v::Vector)
 local w;
 w:=v;
 w:=[-1,-2,-3];
 w
end proc:
v1:=Vector([1,2,3]):
v2:=switch(v1);
v1;

 

v1 remain unchanged.

But it cause the problem if one changes one element at time, instead of complete assignment, as in:

restart;
with(LinearAlgebra):
switch:=proc(v::Vector)
 local w;
 w:=v;
 w[1]:=-1;
 w
end proc:
v1:=Vector([1,2,3]):
v2:=switch(v1);
v1;

 

Mathematica does not have this confusing behaviour. 

switch[v_] := Module[{w = v},
   w = {-1, -2, -3};
   w
   ];
v1 = {1, 2, 3};
v2 = switch[v1]

v1 remains the same here (like Maple). And

switch[v_] := Module[{w = v},
   w[[1]] = -1;
   w
   ];
v1 = {1, 2, 3};
v2 = switch[v1]

Here also v1 remains unchanged, as expected.  This is the behavior one would expect.  Notice that Mathematica does not have Vector or Matrix special structures, as every is list of lists. Maple behaves the same if ones uses list instead of Vector as well.

Maple seems to always convert sqrt(2)*exp(I*Pi/4)  to 1+I.

 

sqrt(2)*exp(I*Pi/4);

           sqrt(2)*((1/2)*sqrt(2)+I*sqrt(2)*(1/2))

simplify(%);

           1+I

If you want just to print it. you can do

p:=convert(z,polar);
sprintf("%s%a%s%a%s","the number is ", op(1,p), " exp(",(I*op(2,p)), ")");

                           the number is 2^(1/2) exp(1/4*I*Pi)

This is one of those things where CAS does automatic simplification.

Somethink like Matlab pause statment

 

try Threads:-Sleep(n); which maps to Matlab pause(n)

see https://www.maplesoft.com/support/help/maple/view.aspx?path=Threads%2fSleep

I am sure there is faster way, but this seems to give 5.

restart;
A := 11:
B := 21:
a := convert(A, base, 3);
a := ListTools:-Reverse(a);
b := convert(B, base, 3);
b := ListTools:-Reverse(b);
c := parse(cat(op(a)))+parse(cat(op(b)));
c := ListTools:-Reverse(convert(c, base, 10));
c := map(x->`mod`(x,3),c);
c := parse(cat(op(c)));
c := convert(c, base, 10);
c := convert(c,'base',3,10);
c := parse(cat(op(c)));

       5

it works for me on Maple 2018

PDE := diff(u(x, y), x, x)+diff(u(x, y), y, y)-6*x*y*(1-y)-2*x^3; 
BCs := u(0, y) = 0, u(1, y) = y*(1-y), u(x, 0) = 0, u(x, 1) = 0;
pdsolve({PDE,BCs},u(x,y));

 

2 3 4 5 6 7 8 Page 4 of 9