Maple 2017 Questions and Posts

These are Posts and Questions associated with the product, Maple 2017

Dear Maple users, m

I am willing to convert a Matlab text into Maple and create a Maple procedure that can compute the same, but since I never used Matlab I have no idea of the input.

I used the: Matlab[FromMFile]("covMarket.m", "mapleout.mpl"); to convert. But there is nothing converted actually, 

So I am wondering, can anybody help converting it and posting the converted maple text into the answers? If there are lots of work to be done, please at least show me what to do. Thanks in advance

Below is the Ledoit and Wolf, shrinkage estimator script in Matlab:

function [sigma,shrinkage]=covMarket(x,shrink)

% function sigma=covmarket(x)
% x (t*n): t iid observations on n random variables
% sigma (n*n): invertible covariance matrix estimator
%
% This estimator is a weighted average of the sample
% covariance matrix and a "prior" or "shrinkage target".
% Here, the prior is given by a one-factor model.
% The factor is equal to the cross-sectional average
% of all the random variables.

% The notation follows Ledoit and Wolf (2003)
% This version: 04/2014

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This file is released under the BSD 2-clause license.

% Copyright (c) 2014, Olivier Ledoit and Michael Wolf 
% All rights reserved.

% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:

% 1. Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.

% 2. Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in the
% documentation and/or other materials provided with the distribution.

% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
% IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
% THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
% PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
% CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
% EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
% PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
% LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
% NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% de-mean returns
t=size(x,1);
n=size(x,2);
meanx=mean(x);
x=x-meanx(ones(t,1),:);
xmkt=mean(x')';

sample=cov([x xmkt])*(t-1)/t;
covmkt=sample(1:n,n+1);
varmkt=sample(n+1,n+1);
sample(:,n+1)=[];
sample(n+1,:)=[];
prior=covmkt*covmkt'./varmkt;
prior(logical(eye(n)))=diag(sample);

if (nargin < 2 | shrink == -1) % compute shrinkage parameters
  c=norm(sample-prior,'fro')^2;
  y=x.^2;
  p=1/t*sum(sum(y'*y))-sum(sum(sample.^2));
  % r is divided into diagonal
  % and off-diagonal terms, and the off-diagonal term
  % is itself divided into smaller terms 
  rdiag=1/t*sum(sum(y.^2))-sum(diag(sample).^2);
  z=x.*xmkt(:,ones(1,n));
  v1=1/t*y'*z-covmkt(:,ones(1,n)).*sample;
  roff1=sum(sum(v1.*covmkt(:,ones(1,n))'))/varmkt...
      -sum(diag(v1).*covmkt)/varmkt;
  v3=1/t*z'*z-varmkt*sample;
  roff3=sum(sum(v3.*(covmkt*covmkt')))/varmkt^2 ...
      -sum(diag(v3).*covmkt.^2)/varmkt^2;
  roff=2*roff1-roff3;
  r=rdiag+roff;
  % compute shrinkage constant
  k=(p-r)/c;
  shrinkage=max(0,min(1,k/t))
else % use specified number
  shrinkage = shrink;
end

% compute the estimator
sigma=shrinkage*prior+(1-shrinkage)*sample;


 

MAPLE CODE [below link]:


Dispersion.mw

range of "kx" variable [0 to 8x106] and range of "f" variable  [80x1012 to 220x1012]

Why different between calculate two form? I use maple 2017

evalf(sech(20)^2); evalf(sech(-20)^2);
                                     
                       1.699341702 *10^ -17  
                                     
                       1.699341702 *10^ -17  
evalf(1-tanh(20)^2); evalf(1-tanh(-20)^2);
                               0.
                               0.

 

This may be a frequently asked question but I could not find

it in MaplePrime's archives.

 

The expression

z := (x^(a+1) - x^a)/(x-1);

(x^(a+1)-x^a)/(x-1)

should simplify to x^a. I don't know how to do that in Maple 2017.

I have tried all sorts of commands and assumption but none

worked.  For instance:

simplify(z) assuming x>1, a::posint;

(x^(a+1)-x^a)/(x-1)

What's the trick?

Hi, I use Maple 2017 on Windows 10 Pro. When I try to save a package that was included with the book entitled
"Finite Elements Using Maple - A Symbolic Programming Approach" by A. Portela and A. Charafi, Springer Verlag, Berlin, Heidelberg, 2002, with the line: "savelib('Plotter'):", maple return the error "Error, cannot open archive, C:\Program Files\Maple 2017\lib, for writing.". Someone can help me? Tank you.

Hi All,

I would like to generate a sequence (say 10) of points <x_i,y_i>. (i=1, 2,..,10.)

There is a predefined constraint like f(x_i,y_i)=0.01. And I don't know the close form of f() (becasue there is a intermediate parameter in f() that was caculated numerically by optimization.).

Is there any simple function, e.g. a variant of seq(), that can do this? I am looking for something looks like:

seq(f(x,y)=0.01, x=0..1, y=0..1, 0.1)

Thanks.

Hi,
First of all I am not an expert in using Maple. 
When I execute the following code, it runs without an error:
----------------
restart;  

with(plots):

g:=(x,y)->sin(((1+x^2+y^2))*(Pi/2)) ;                                                                            

 q:=(n,k,x)->binomial(n,k)*(((1+x)/2)^k)*((1-x)/2)^(n-k) ;                                                            

  K:=(n,m,x,y)->((1+n)/2)*((1+m)/2)*sum(q(n,k,x)*sum(q(m,j,y)*int(int(g(t,u),u=2*(j/(m+1))-1..2*((j+1)/(m+1))-1),t=2*(k/(n+1))-1..2*((k+1)/(n+1))-1),j=0..m),k=0..n);                                                                      

p1:=plot3d(g(x,y),x=-1..1,y=-1..1,color=blue):                                                                       p2:=plot3d(K(30,30,x,y),x=-1..1,y=-1..1,color=brown):                                                                    

display([p1,p2]);
---------
However, when I execute the following code,  I get the error message "to many levels of recursion"
---------
restart;                                                                                                                

with(plots):                                                                                                          

 g:=(x,y)->sin(Pi*(x+y))*(x^2+y^2);                                                                  

 q:=(n,k,l,x,y)->binomial(n,k)*binomial(n-k,l)*(((1+x)/2)^k)*(((1+y)/2)^l)*(1-((1+x)/2)-((1+y)/2))^(n-k-l) ;                                              K:=(n,x,y)->(((1+n)*(2+n))/4)*sum(sum(q(n,k,l,x,y)*int(int(q(n,k,l,t,u)*g(t,u),u=-1..-t),t=-1..1),l=0..n-k),k=0..n);  p1:=plot3d(g(x,y),x=-1..1,y=-1..-x,color=blue):                                                                      

 p2:=plot3d(K(1,x,y),x=-1..1,y=-1..-x,color=brown):                                                                  

p3:=plot3d(K(2,x,y),x=-1..1,y=-1..-x,color=yellow):                                                                

p4:=plot3d(K(5,x,y),x=-1..1,y=-1..-x,color=green):                                                                    

p5:=plot3d(K(10,x,y),x=-1..1,y=-1..-x,color=red):                                                              

   display([p1,p2,p3,p4,p5]);
--------
Could you please help me with this problem. Thanks in advance.

Hello Everybody!
Please help me to find a way to write the Taylor's series of some function in factiorial or Gamma notation.
Please see the attached file and suggest me something.
taylor_series_general.mw

I have the following pertubation problem I want to use maple to expand for me.

 

We have epsilon := eps;

x(t,eps):= x_{-1}(t)/eps+x_0(t)+x_1(t)*eps

z(t,eps):=z_{-1}(t)/eps+z_0(t)+z_1(t)*eps

I want to expand a Taylor series of the following function upto some arbitray order of eps, i.e O(eps^3) or higher (depending on my mood :-)), around t=0, f(x(t,eps),z(t,eps),cos(t/eps),sin(t/eps)).

 

Anyone has any suggestion how to use maple 2017.3 to do this?

Thanks!

 

 

I am trying to define a periodic piecewise function where essentially for every positive integer I have an output of '1' and the output is '0' everywhere else. I want to use this function in defining a Partial Differential Equation as well.

This is how I have been going about it after reading through the answers on similar questions posted before:

f := piecewise(t::posint, 1, 0_otherwise):
p := 1:
fperiodic := eval(f, t = t-p*trunc(t/p)):

But when I plot it to just as a test, I get a dead plot:
plot(fperiodic, t = 0 .. 5)

 


                     
I am hoping for something like:

Please help!
TIA

Hello,

     I've been using the invhilbert procedure from the inttrans package, but I'm running into a small problem. I'm attempting to apply invhilbert to an unknown function, and then later evaluate that function. However, in one particular case (bad, below), it does not produce the expected output. Curiously, I noticed that if I did *two* substitutions (good, below), it produces the expected result.

with(inttrans):

pde := inttrans:-invhilbert(f(t,s),s,x):
def := g = ((t) -> exp(t)*sin(B)):

bad := f = ((t,x) -> (1 + exp(t)*sin(B))*sin(x+A)):
good := f = ((t,x) -> (1 + g(t))*sin(x+A)):

eval['recurse'](pde, [good,def]);
# -cos(A) exp(t) sin(B) cos(x) + sin(A) exp(t) sin(B) sin(x) - cos(A) cos(x) + sin(A) sin(x)
eval['recurse'](pde, [bad,def]);
# -exp(t) sin(B) cos(x) + sin(A) sin(x) - cos(A) cos(x)

As a side-note: this discrepancy was very delicate. Removing any of terms (for instance, A) causes both to give the same, correct answer.

For this particular problem, I was able to manually replace exp(t)*sin(b) with the function g(t) and get the correct result, but I was hoping for a more automated approach (I need to apply it to many equations). Is there any way to get the correct result from equation bad?

Thank you very much!

Hello,

     I've been trying to figure out how to partially expand a trig function using the sum-rule but not the multiple-angle rule. For instance, I would like to expand

sin(2*x+3*y)

to

sin(2*x)*cos(3*y) + cos(2*x)*sin(3*y)

Unfortunately, expand also uses the multiple-angle rules, which is unwanted. The trigsubs command looked promising, but I don't know the names of the variables (x and y here) a priori, so I believe I need something with type matching (like applyrule with x::monomial + y::monomial).

Thanks for your help!

Hello,

     The following system of ODEs is handled correctly by dsolve, but PDEtools:-Solve raises an error:

ranking := [{A(), B(x)}]:
eqn_sys := {D(B)(x) = 0, A()* D(B)(x) = 0}:
dsolve(eqn_sys, ranking);
# {A() = A(), B(x) = _C1}
PDEtools:-Solve(eqn_sys, ranking);
#Error, (in dsolve) found many possible indications of the solving variables as [{B(x)}, [{A(), B(x)}]]

In particular, it seems the error is raised when 1) the ranking is a nested list and 2) at least one of the ranking elements is a function without any arguments.

Admittedly, this is a very strange case, but I did run into this earlier today. Of course, the example here is contrived (the nested-list ranking is completely unnecessary for this example), but it illustrates the error.

As a workaround, I found replacing the function A() with its name A in the ranking solves this problem (it can be left as a function in the system of equations). Nevertheless, I thought I would point this out as it seems dsolve handles this just fine even without the workaround, and presumably PDEtools/Solve should be able to as well.

This seems similar to a previous bug; this bug was fixed in Maple 2018. Unfortunately, I haven't updated yet, so I can't verify if the patch solves this problem as well.

Hello,

     So, dsolve is able to pass arguments through to casesplit. Further, PDEtools/Solve is able to pass arguments through to dsolve. However, it appears PDEtools/Solve isn't able to pass arguments through dsolve to casesplit? For instance, consider the following differential equation:

eq := {diff(A(t),t) = A(t)*x}:
dsolve(eq, {A(t)}, ivars={x,t});
PDEtools:-Solve(eq, {A(t)}, ivars={x,t});

Here, I'm considering both x and t to be independent variables (hence, A(t) should not depend on x).

In that case, dsolve correctly gives the only solution as A(t) = 0. However, PDEtools/solve doesn't seem to pass-through the ivars option and incorrectly gives A(t) = _C1*exp(x*t) as a solution.

Is there another way to have PDEtools pass this option through to casesplit?

Thanks!

Hello, when I write a large document block in maple and want to do some operations, maple shows wait cursor (hourglass) for 2-3 minutes again and again. I attached a sample file below. 

I found out when maple is installed , javaw.exe also instal and when I open bellow file, the javaw use 15% of cpu and this cause maple works slowly. 

the attached file is just an example for large document block and I undrestand that it can be simplified. I want to know how to handle large expressions generally?

K-Euler_Lagrange.mw

 

First 14 15 16 17 18 19 20 Last Page 16 of 40