Maple 2017 Questions and Posts

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

Can I somehow define a function based on a result from a PolynomialFit.
It doesn't seem to read it as a function the way I try to define it now (see attached maple file).

I could copy the result into a function, but then I lose some information since the values are approximated.

Define.mw

I am trying to find an eigenspace of a matrix, but I am getting an error. I have attached a screenshot of the error and my work to help. 

Dear Friends

Do I want to know how to merge these two loops in one? how to apply if-else loop? help me in this regard. the source file is attached. Thank you! 

restart; M := 5;
for i1 while i1 <= M do N[i1, 0](u) = 1 end do;
                         N[1, 0](u) = 1
                         N[2, 0](u) = 1
                         N[3, 0](u) = 1
                         N[4, 0](u) = 1
                         N[5, 0](u) = 1
for k1 while k1 <= M do N[0, k1](u) = 0 end do;
                         N[0, 1](u) = 0
                         N[0, 2](u) = 0
                         N[0, 3](u) = 0
                         N[0, 4](u) = 0
                         N[0, 5](u) = 0

 

Hi,

 

I am trying to make Maple replace some expressions with variables so that I'll be able to get the coefficients of the resulting polynomial. 

I have the following piece of code:

h := map(proc(x) convert(x,parfrac,s,complex) end proc,convert(f,parfrac,t,complex));

for sub_var in subs do
               h:=applyrule(sub_var[1]=1/sub_var[2],h);

end do;

subs is a list automatically generated in a different procedure, here is a sample list:

[[t-3*I, a1], [t+3*I, b1], [s-3*I, c1], [s+3*I, d1], [t-.4948716594-.4285714286*I, a2], [t-.4948716594+.4285714286*I, b2], [s-.4948716594-.4285714286*I, c2], [s-.4948716594+.4285714286*I, d2], [t+.4948716594-.4285714286*I, a3], [t+.4948716594+.4285714286*I, b3], [s+.4948716594-.4285714286*I, c3], [s+.4948716594+.4285714286*I, d3]]

f is a rational function that breaks up nicely into partial fraction due to theoretical reasons. here is a sample:
f: = (1/2)*(3969*I)*(35*s^3*t^3+21*s^3*t-9*s^2*t^2+21*s*t^3+45*s^2+63*s*t+45*t^2+27)*(t^2+1)*(s^2+1)/(((27*I)*t^2+7*t^3-9*I-21*t)*((27*I)*s^2-7*s^3-9*I+21*s)*((27*I)*s^2+7*s^3-9*I-21*s)*((27*I)*t^2-7*t^3-9*I+21*t))
These particular samples have algebraic numbers in them. and that makes apply rule fail, it seems to only work if the numbers are rational. Any idea on how can I fix that? Alternatively, replace applyrule all together with something that actually works?

Thanks

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!

5 6 7 8 9 10 11 Last Page 7 of 31