MaplePrimes Questions

Hi guys! First time posting here and I'm very new to Maple too.

I'm using maple right now to calculate statics problems, and for that we've customized some units to better fit what we're working with and want to see in output. In general, it's working great, but sometimes when I try to use the solve function including these units, I get an error mesage I don't really understand..

Here's the unit customization:

restart;
with(Units); AddSystem(NewSI, GetSystem(SI), kN*m, kN/m, kN, MPa); UseSystem('NewSI');
Automatically loading the Units[Natural] subpackage 

Error, (in Units:-AddSystem) expecting a unit but got `Units:-Unit(kN*m)`
with(Units[Natural]);
 
- As said, in general I have no problems, despite the error message above, it's only when using the solve function as follows:
 
(I've defined A,B,C and G, all with results in kN)
solve(OL-A-B-C-G=0,OL)
 
Then it gives me this error:
Error, (in Units:-Standard:-+) the units `1` and `kN` have incompatible dimensions
 
What I want here is to setup an equilibrium equation, and then solve for the variable OL, which should be output in kN. 
First of all, I don't really understand what Maple is trying to tell me here?
-I figure it has something to do with the new units i'm adding, and when if I'm putting the units commands into the startupcode customizer, it tells me another error:
Error: (in Units:-AddSystem) expecting a unit but got `Units:-Unit(kN*m)
 
But I don't know how to do something about this, the new units I defne is simply something I've cpoy/pasted from another source, I don't have any knowledge about how to customize the system myself..
Googling this problem only leads me to the maple help websites, but that doesn't help me as I'm completely new to all this...

So I was hoping someone could help me fix the error(s), or at least understand what the errors mean..

 

How can I get the vlalue of x, y and z into an expression?

In example here I would like to know the value of 2x+3y+z

many thanks


I'm hoping somebody can help with this problem.

The Poisson Loss Function is defined by the series:

L := sum((n-s)*lambda^n*exp(-lambda)/factorial(n), n = s .. infinity)

Where lambda is the mean value that is prescribed and s is the variable in question.

Now, if the value of L is given, can anyone tell me how to solve for  s?

Poisson Distribution Loss Function Tables are available and give values for s for a given lambda, so I's like to see if Maple can handle this.

 

Thanks for reading!

How do I get Maple to reduce/simplify the following difference quotient to its lowest terms? Basically I need Maple to rationalize the numerator. Any suggestions on how to do this?

f := proc (x) options operator, arrow; sqrt(2*x+1) end proc

proc (x) options operator, arrow; sqrt(2*x+1) end proc

(1)

expand((f(x+h)-f(x))/h)

(2*x+2*h+1)^(1/2)/h-(2*x+1)^(1/2)/h

(2)

simplify((f(x+h)-f(x))/h)

((2*x+2*h+1)^(1/2)-(2*x+1)^(1/2))/h

(3)

rationalize((f(x+h)-f(x))/h)

((2*x+2*h+1)^(1/2)-(2*x+1)^(1/2))/h

(4)

``


 

Download rationalize.mw

Consider the `or` procedure.
`or`(x, y)  should be equivalent to  x  or  y.

However:
restart;
x := a=0;
y := b=0;

                           x := a = 0
                           y := b = 0
x or y;
                             false
`or`(x,y);
                         a = 0 or b = 0
%;
                             false
simplify(`or`(x,y));
                         a = 0 or b = 0
eval(`or`(x,y));
                             false


### So,  `or`(x,y)  is not fully evaluated [or simplified?].
### Is this documented somewhere?


# Similarly
`not`(x);
                           not a = 0
%;
                              true
not x;
                              true

 

Hello! 

I am currently programming the Anderson Acceleration for fixed point iteration in Maple. The algorithm comes from Walker et al. 2011 (ANDERSON ACCELERATION FOR FIXED-POINT ITERATIONS) (if you are interested in this problem please read the short paper). The code that Walker supplies runs fine in Matlab, with qrdelete as a built-in function. However in Maple I have decided to skip operations on QR, and instead opted to create a new QR every time I increase or decrease the amount of residuals df. However, here comes the kicker, somehow Maple decides to turn a vector or matrix into a procedure when I Concatenate, or DeleteColumn. I could really use a working Anderson Acceleration code for my research (my research is not based on AA or root solvers in general, but spectral methods). I will paste the entire code here. This is my attempt at getting Walker's original Matlab code to work in Maple.

I could use some pointers and tips. Can you program this in a more efficient way? I would be happy to learn. *Notice that the code works for a host of different equations, but not all. Feel free to let me know if this question or inquiry is inappropriate and I will of course delete the post.

restart:
Digits:=12:
Runtime:=time():
with(LinearAlgebra):
with(plots):
with(orthopoly):
with(ArrayTools):
    

phix := Vector(2):
X    := Vector(2):
phix[1] := cos(x[2]):
phix[2] := 3*cos(x[1]):
X[1] := 0.0:
X[2] := 0.0:

#Code AndersonAcceleration.
AndersonAcceleration:=proc(N,phi,X0)
global x, xS, here1, here2;
local mMax, itmax, atol, rtol, droptol, beta, AAstart, res_hist, df, DGg, gamma;
local DG, mAA, iter, gval,fval,res_norm, tol, f_old, g_old, y, i, k, Q, R, QRg, dfT, DGT;

(*
%------------------------------------------------------------------------
% Function xS = AndersonAcceleration(N,phi,x0).
%
% Fixed-point iteration with or without Anderson acceleration.
% 'phi' is the fixed point iteration map and 'xS' is the 
% solution, so that xS = phi(xS).
%
% Input arguments:
%    X0 = Initial value solution. Note: In this function this variable 
%        must be a column vector.
%       1. 'mMax' = maximum number of stored residuals (non-negative integer).
%       NOTE: 'mMax' = 0 => no acceleration. default=1000
%       2. 'itmax' = maximum allowable number of iterations. default=1000
%       3. 'atol' = absolute error tolerance. default=1.0e-6
%       4. 'rtol' = relative error tolerance. default=1.0e-3
%       5. 'droptol' = tolerance for dropping stored residual vectors to 
%       improve conditioning: If 'droptol' > 0, drop residuals if the
%       condition number exceeds droptol; if droptol <= 0,
%       do not drop residuals.
%       6. 'beta' = damping factor: If 'beta' > 0 (and beta ~= 1), then 
%       the step is damped by beta; otherwise, the step is not damped.
%       NOTE: 'beta' can be a function handle; form beta(iter), where iter 
%       is the iteration number and 0 < beta(iter) <= 1.
%       7. 'AAstart' = acceleration delay factor: If 'AAstart' > 0, start 
%       acceleration when iter = AAstart.
%
% Output:
% xS = Solution vector.
%
% The notation used is that of H.F. Walker: Anderson Acceleration:
% Algorithms and implementation
%------------------------------------------------------------------------
*)

mMax    := 1000:
itmax   := 1000:
atol    := 1.0e-8:
rtol    := 1.0e-12:
droptol := 1.0e4:
beta    := 1.0:
AAstart := 0:

# Initialize storage arrays and number of stored residuals.
DG := Matrix():
df := Matrix():
DGg := Vector(N);
QRg := Vector(N);
mAA := 0:

for iter from 0 to itmax do

   x:=X0:
   gval := Vector(phi):
   fval := gval - X0:
   res_norm := norm(fval,2):
   print(res_norm);    
   # Set the residual tolerance on the initial iteration.
   if iter = 0 then
      tol := max(atol,rtol*res_norm):
   fi:
    
   # Convergence test, if converged the loop stops.
   if res_norm <= tol then
      print(res_norm);
      break;   # Breaks for-loop
   fi:
    
   # If resnorm is larger than 1e8 at iter > 5, problem stops
   if res_norm >1e8 and iter > 5 then
      print(res_norm);
      break; # Breaks for-loop, diverged
   fi:

   # Fixed point iteration without acceleration, if mMax == 0.
   if mMax = 0 or iter < AAstart then
      # We update E <- g(E) to obtain the next approximate solution.
      for i from 1 to N do
         X0[i] := gval[i]:
      od:
   else
      # With Anderson acceleration.
      # Update the df vector and the DG array.
      if iter > AAstart then
         if mAA < mMax or Size(df,2) = 1 then
            print(whattype(df));
            df := Concatenate(2,df,fval-f_old):
            DG := Concatenate(2,DG,gval-g_old):
         else 
            df := Concatenate(2,df[..,-1],fval-f_old):
            DG := Concatenate(2,DG[..,-1],gval-g_old):   
         fi:
         mAA := mAA + 1:
      fi:   # iter
      print(iter,mAA);
      print(whattype(df));
      # We define the old g and f values for the next iteration
      f_old := fval;
      g_old := gval;
      
      if mAA = 0 then
         # Initialization
         # If mAA == 0, update X <- g(X) to obtain themah next approximate
         # solution. No least-squares problem is solved for iter = 0
         for i from 1 to N do
            X0[i] := gval[i]:
         od:
      else
         if mAA > 1 then
            Q,R := QRDecomposition(df,datatype=float);
            while ConditionNumber(R) > droptol do
                if mAA = 2 then
                   print('here1'):
                   df := convert(DeleteColumn(df,1),Vector);
                   DG := convert(DeleteColumn(DG,1),Vector);
                else
                   df := DeleteColumn(df,1);
                   DG := DeleteColumn(DG,1);
                fi:
                Q,R := QRDecomposition(df,datatype=float);
                mAA := mAA - 1;
                print(Q,R,mAA);
            od:
          
            if Size(df,2) > 1 then
               print(Q,R);
               gamma := LeastSquares([Q,R],fval);
               print(gamma);
            else
               R := norm(df,2);
               Q := MTM[mldivide](R,df);
               gamma := MTM[mldivide](R,Transpose(Q).fval);
               print(gamma);
            fi:
         else
            R := norm(df,2);
            Q := MTM[mldivide](R,df);
            gamma := MTM[mldivide](R,Transpose(Q).fval);
         fi:
 
         if Size(gamma,1) > 1 then
            DGg:=DG.gamma:
         else
            DGg:=DG*gamma;
         fi:

         # Update the approximate solution.
         for i from 1 to N do
            X0[i] := gval[i] - DGg[i];
         od:
         print('Sol',X0);
         
         # Damping for non-zero beta
         if beta > 0 and beta <> 1 then
            if mAA = 1 then
               QRg := Q*R*gamma;
            else
               QRg := df.gamma;
            fi:
            for i from 1 to N do
               X0[i] := X0[i] - (1-beta)*(fval[i] - QRg[i]);
            od:
         fi:# isa(beta ...
         print(iter,mAA);
      fi: # mAA = 0
   fi:# mMax == 0

od:
xS := Vector(N);
for i from 1 to N do xS[i]:=X0[i]: od:
return xS
end:

AndersonAcceleration(2,phix,X):


 

Is there already a build in sum(), add() procedure where you can supply a condition?

I know the help doesn't say anything about it, but I thought maybe there is something else.

Say I want to add the coefficients a(n) up to N, but only if n divides N, so

add(a(n),n=1..N,conditioner: mod(N,n)=0)

Thanks

how can I get the first function acting on the symbolic expression as below(in this case log)

expr :=sin(abs(log(a+b*c)));


I need to solve for many unknown expressions. It would be great if I can able to get all functions in sequential order acting.

I got to know using op i can solve if only one function is action like below

expr := sin(a+b*c)
then op(0,expr) #gives sin

op(1,expr) # gives a+b*c


I have the following Maple code.

 

x := [5, 10, 15, 20];

y := [4.22, 7.49, 12.24, 19.60];  

yui := [2.48, 3.76, 6.11, 14.60];

yli := [2.27, 3.34, 6.09, 10.90];

 

with(Statistics): with(plots):

p1 := ErrorPlot(y, coords = x, yerrors = yui);

this produces a plot with error bars. The problem is that I acutally have unequal errors. In the ErrorPlot helpfile it says:

"This options specifies errors along the x-axis. The array of errors must have the same number of elements. To specify right errors and left errors separately, use the list of two vectors." (this pertains to xerrors obviously but below it says the same applies to yerrors)

I have tried entering the code above with yerrors=[yli,yui] and with yerrors={yli,yui}....but neither option works and I get the error:

"Error, invalid input: Statistics:-ErrorPlot expects value for keyword parameter yerrors to be of type {identical(default), [{array, list, rtable, DataFrame, DataSeries}, {array, list, rtable, DataFrame, DataSeries}], {array, list, rtable, DataFrame, DataSeries}}, but received {[2.27, 3.34, 6.09, 10.90], [2.48, 3.76, 6.11, 14.60]}"

Can anyone advise me on what I'm doing wrong - I am very new to Maple.

Jo

 

Dear all, I am having difficuty in executing the following program. the error message reads "Error, unable to compute coeff". Secondly the solution and the graph of the equation could not display.Attached is the prime_question.mw
 

 

Download prime_question.mw
 

restart; with(student)

n := 2;

2

(1)

v := sum(u[i]*p^i, i = 0 .. 2);

p^2*u[2]+p*u[1]+u[0]

(2)

f := proc (x) options operator, arrow; e^x+(1/2)*x*(e^(2*x)-1) end proc;

proc (x) options operator, arrow; e^x+(1/2)*x*(e^(2*x)-1) end proc

(3)

k := proc (x, t) options operator, arrow; x end proc;

proc (x, t) options operator, arrow; x end proc

(4)

F := proc (u) options operator, arrow; u(x)^2 end proc;

proc (u) options operator, arrow; u(x)^2 end proc

(5)

u[0] := f(t);

e^t+(1/2)*t*(e^(2*t)-1)

(6)

for i to 2 do u[i] := expand(subs(x = t, int(coeff(p*k(x, t)*F(v), p^i), t = 0 .. x))) end do

Error, unable to compute coeff

 

s := value(sum(Eu[k], k = 0 .. 2*e));

sum(Eu[k], k = 0 .. 2*e)

(7)

U := proc (x) options operator, arrow; collect(s, x) end proc;

proc (x) options operator, arrow; collect(s, x) end proc

(8)

with*plots:

p1 := plot*(exact*solution, t = 0 .. T, style = point):

p2 := plot*(U(t), t = 0 .. T, style = line):

plots*([display])(p1, p2);

plots*[display(plot*(exact*solution, t = 0 .. T, style = point), plot*(sum(Eu[k], k = 0 .. 2*e), t = 0 .. T, style = line))]

(9)

``

``


 

Download prime_question.mw

 

 

file

I am using DirectSearch package for optimization. I am using GlobalOptima function. I want to see the settings and results such as initial points, number of iterations, residuals etc. I tried using infolevel[Directsearch] but couldn't see any results. Let me know if there is any other command to get this information.

I want to ask you, Is there any inequality for |cosh(x)|? I have read that cosh(x)<= e^(x^(2)/2).

Hello here is a description of my issue:

1. I created a new code edit region

2. i put some code in the code edit region 

3. In the context Panel I unchecked the 'visible' setting for the code edit box

When I evaluate the worksheet the code in the code edit region still runs, but I can't figure out how to edit the code in that region. There is not an icon to open the code edit region as there would be had I toggled the 'expand' setting. Furthermore, I can't select the invisible code edit region in order to toggle the 'visible setting'.

How can I make the code edit region visible again?

 

Thanks for you help

This is my original question, but I can't ask, so I put it here.

I have a system of pde, and it's hard to solve.

But I want to find the type of solutions which are polynomials of degree n of the several independent variables.

Is it possible using 'pdsolve'? Or there are some other commands in Maple to do that?

Thanks!

Sorry, I comment not for answering question.

I want to ask a question, but I can't enter any 'Tags', but they need at least one tag.

There is not any text box where I can enter a tag.

Who can help me?

thanks!

1 2 3 4 5 6 7 Last Page 2 of 1657