Maple_lover1

125 Reputation

7 Badges

6 years, 125 days

MaplePrimes Activity


These are questions asked by Maple_lover1

What is your choice for creating a good table?

For example;

 

f:=(x,t)->x*t;
g:=(x,t)->x^2*t;

How to create a table as follows? (Appearance similar to the following is not required. I am open to all options)

Dear there,

I want to create a new package. 

Goal of the package:

I have two functions psi(n,m,x) and w(n,x).

 

These functions are defined differently in case A, and in case B

 

In my future works,

I want to use the functions psi(n,m,x) and w(n,x) in ONE (same) worksheet by calling the package.

 

Case A;

 K:=2^(k-1):
with(orthopoly): 
psi:=(n,m,x)->piecewise((n-1)/K <= x and x <= n/K,
(sqrt((m+1/2)*2^k))*LegendreP(m,2^k*x-2*n+1), 0);   
w:=(n,x)->1;  
 

 

Case B;

K:=2^(k-1):
with(orthopoly):
unprotect(gamma):
h:=(m,epsilon,gamma)->2^(epsilon+gamma+1)*GAMMA(epsilon+m+1)*GAMMA(gamma+m+1)/((2*m+1+epsilon+gamma)*m!*GAMMA(epsilon+gamma+1));


psi:=(n,m,x)->piecewise((n-1)/K <= x and x <= n/K,  2^(k/2) *h(m,epsilon,gamma)*simplify(JacobiP(m,epsilon,gamma,2^(k)*x-2*n+1)), 0); 
  

w:=(n,x)->(1-x)^(epsilon)*(1+x)^gamma; 

How can we achieve this in the simplest way?

 

MY TRY: (Please click to download the code.mw)

test:=module()
export functionA,functionB;
 option package;


######################################################
functionA:=proc(k,M) local K,h,psi,w; 
K:=2^(k-1):
with(orthopoly): 
psi:=(n,m,x)->piecewise((n-1)/K <= x and x <= n/K,
(sqrt((m+1/2)*2^k))*LegendreP(m,2^k*x-2*n+1), 0);   
w:=(n,x)->1;   
return psi(n,m,x) ,w:
end proc:
######################################################


functionB:=proc(k,M,epsilon,gamma) local K,h,psi,w; 
K:=2^(k-1):
with(orthopoly):
unprotect(gamma):
h:=(m,epsilon,gamma)->2^(epsilon+gamma+1)*GAMMA(epsilon+m+1)*GAMMA(gamma+m+1)/((2*m+1+epsilon+gamma)*m!*GAMMA(epsilon+gamma+1));


psi:=(n,m,x)->piecewise((n-1)/K <= x and x <= n/K,  2^(k/2) *h(m,epsilon,gamma)*simplify(JacobiP(m,epsilon,gamma,2^(k)*x-2*n+1)), 0); 
  

w:=(n,x)->(1-x)^(epsilon)*(1+x)^gamma;   
return psi(n,m,x),w(n,x):
end proc:
######################################################

end module;


savelib(test):


# FOR EXAMPLE
restart:
with(test);

#For k=2,M=3 in FunctionA, let's calculate values of "Psi(2)" and "w(2,x)"
k:=2:
M:=3:
K:=2^(k-1):
N:=K*M:
(psi,w):=functionA(2,3):
psi:=(n,m,x)->psi; 
w:=(n,x)->w;
unprotect(Psi):
Psi:=x->Array([seq(seq(psi(i,j,x),j=0..M-1),i=1..K)] )^+:
Psi(2);
w(2,x);


#Now, let's calculate values of "Psi(2)" and "w(2,x)" For  k=3,M=4, epsilon=1, gamma=2 in FunctionA 

 (psi,w):=functionB(3,4,1,2):
Psi(2);
w(2,x);

 

 

 

I usually piecewise functions in my maple codes. I want to export  the my maple code to a Matlab code in order to utilize advantages of plots of Matlab.

What methods would you recommend me?

 

For example:

Suppose that I have a piecewise u function.

restart:
u:=1/(1. + exp(x))^2 + 1/(1. + exp(-5.*t))^2 - 0.2500000000 + x*(1/(1. + exp(1 - 5*t))^2 - 1./((1. + exp(-5*t))^2) + 0.1776705118 + 0.0415431679756514*piecewise(0. <= t and t <= 0.5000000000, 1.732050808, 0.) + 0.00922094377856479*piecewise(0. <= t and t <= 0.5000000000, 30.98386677*t - 7.745966692, 0.) + 0.0603742508215732*piecewise(0.5000000000 <= t and t <= 1., 1.732050808, 0.) - 0.00399645630498528*piecewise(0.5000000000 <= t and t <= 1., 30.98386677*t - 23.23790008, 0.)) + (-0.00243051684581302*piecewise(0. <= x and x <= 0.5000000000, 1.732050808, 0.) - 0.000809061198761621*piecewise(0. <= x and x <= 0.5000000000, 30.98386677*x - 7.745966692, 0.) - 0.0152377552205917*piecewise(0.5000000000 <= x and x <= 1., 1.732050808, 0.) - 0.00195593427342862*piecewise(0.5000000000 <= x and x <= 1., 30.98386677*x - 23.23790008, 0.))*piecewise(0. <= t and t <= 0.5000000000, 1.732050808, 0.) + (-0.000433590063316381*piecewise(0. <= x and x <= 0.5000000000, 1.732050808, 0.) - 0.000146112803263678*piecewise(0. <= x and x <= 0.5000000000, 30.98386677*x - 7.745966692, 0.) - 0.00319022339097685*piecewise(0.5000000000 <= x and x <= 1., 1.732050808, 0.) - 0.000477063086307787*piecewise(0.5000000000 <= x and x <= 1., 30.98386677*x - 23.23790008, 0.))*piecewise(0. <= t and t <= 0.5000000000, 30.98386677*t - 7.745966692, 0.) + (-0.00276114805649180*piecewise(0. <= x and x <= 0.5000000000, 1.732050808, 0.) - 0.000933166016624500*piecewise(0. <= x and x <= 0.5000000000, 30.98386677*x - 7.745966692, 0.) - 0.0207984584912892*piecewise(0.5000000000 <= x and x <= 1., 1.732050808, 0.) - 0.00314360556336114*piecewise(0.5000000000 <= x and x <= 1., 30.98386677*x - 23.23790008, 0.))*piecewise(0.5000000000 <= t and t <= 1., 1.732050808, 0.) + (0.000172746997599710*piecewise(0. <= x and x <= 0.5000000000, 1.732050808, 0.) + 0.0000586775450031145*piecewise(0. <= x and x <= 0.5000000000, 30.98386677*x - 7.745966692, 0.) + 0.00136190009033518*piecewise(0.5000000000 <= x and x <= 1., 1.732050808, 0.) + 0.000211410172315387*piecewise(0.5000000000 <= x and x <= 1., 30.98386677*x - 23.23790008, 0.))*piecewise(0.5000000000 <= t and t <= 1., 30.98386677*t - 23.23790008, 0.);

 

 

I use the following code to transform a Matlab code, but the output is not working in Matlab.

 

with(CodeGeneration):
 	
Matlab(u,resultname="w");

 

I have a matrix as follows.

How do we equalize this matrix to zero matrix and solve it?
 

A:=Matrix(2, 2, [[-0.0001633261895*z[1, 2]^2 + 0.0002805135275*z[1, 2]*z[2, 2] - 0.0001200583046*z[2, 2]^2 + 0.0006934805795*z[1, 1]^2 - 0.001190280265*z[1, 1]*z[2, 1] + 0.00007689977894*z[1, 1]*z[1, 2] - 0.00009937418547*z[1, 1]*z[2, 2] + 0.0005090615773*z[2, 1]^2 - 0.00003303758400*z[2, 1]*z[1, 2] + 0.00005683264925*z[2, 1]*z[2, 2] + 0.7021232886*z[1, 1] - 0.3171553245*z[1, 2] - 0.08291569324*z[2, 1] + 0.04647270631*z[2, 2] - 0.1436869545, 0.0002939068385*z[2, 1]^2 + 0.4237544799*z[1, 1] - 0.03129537402*z[1, 2] - 0.06276282411*z[2, 1] + 0.02529757039*z[2, 2] + 0.0004003811990*z[1, 1]^2 + 0.0002177682527*z[1, 1]*z[1, 2] - 0.0006872086309*z[1, 1]*z[2, 1] - 0.0001976167183*z[1, 1]*z[2, 2] - 0.0001764013184*z[2, 1]*z[1, 2] + 0.0001600777394*z[2, 1]*z[2, 2] - 0.1237363898], [0.00006763201108*z[2, 1]*z[1, 2] - 0.0001020812322*z[1, 2]*z[2, 2] - 0.00001554113990*z[2, 1]*z[2, 2] - 0.00003577693711*z[1, 1]*z[1, 2] + 0.0004330743651*z[1, 1]*z[2, 1] - 0.00001941220415*z[1, 1]*z[2, 2] - 0.01736180925 + 0.5623450996*z[2, 1] - 0.2353707048*z[2, 2] - 0.0003226356619*z[1, 1]^2 + 0.00007598605473*z[1, 2]^2 - 0.0001392051452*z[2, 1]^2 + 0.00003283047567*z[2, 2]^2 + 0.04653058230*z[1, 1] - 0.03026711709*z[1, 2], -0.00008037012799*z[2, 1]^2 + 0.03994641178*z[1, 1] - 0.02291248064*z[1, 2] + 0.3140461555*z[2, 1] + 0.01853659924*z[2, 2] - 0.0001862737861*z[1, 1]^2 - 0.0001013147396*z[1, 1]*z[1, 2] + 0.0002500356011*z[1, 1]*z[2, 1] + 0.00005403916772*z[1, 1]*z[2, 2] + 0.00008206914192*z[2, 1]*z[1, 2] - 0.00004377396755*z[2, 1]*z[2, 2] - 0.01370765196]])

And then, I want to select the roots in which 0<z[i,j]<1. 

Finally, I want to create matrix Z from these roots as follows   

Z:=Matrix(2, 2, [z[1, 1], z[1, 2],z[2, 1], z[2, 2]]);
restart;
PDE := diff(y(x,t), x,x,x,x)+(diff(y(x, t), t,t))=0;  
# Initial/boundary conditions 
  BCs:=y(0,t) = 0, y(1,t) = 0,D[1](y)(0,t)=0,D[1](y)(1,t)=0;

  ICs:=y(x,0) =0, D[2](y)(x,0)=1 ;
  num_solution := pdsolve(PDE, {BCs,ICs}, numeric); 
  num_solution :-plot3d(x=0..1, t=0..1);

1st Question:How to plot the 2D at point x=0.5?

 

2nd Question: How to use PDEplot?

1 2 3 Page 2 of 3