Carl Love

Carl Love

28065 Reputation

25 Badges

13 years, 20 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

To get terms without a[j], a[j+1/2], and a[j+1], just set those variables to 0:

eval(eq7, [a[j]= 0,  a[j+1/2]= 0,  a[j+1]= 0]);

It seems so simple that I wonder if I am understanding your question correctly.

f:= x->x^2:  xticks:= [2,8]:
plot(f, 0..10, labels= [x,y], tickmarks= [xticks, f~(xticks)], gridlines);

I guessed that you might like the gridlines option also, but you can just take that out if you don't want it.

It seems to me that the tipping and capping will come automatically if you simply apply your procedure violinplot to a KernelDensityPlot with the ranging options. In particular, to enforce positivity, in the below example I use the left= 0 option.

violinplot:= proc()
   local P;
   P:= Statistics:-KernelDensityPlot(args);
   plots:-display(
      plottools:-rotate(
         plots:-display(P, plottools:-reflect(P, [[0,0], [1,0]]))
        ,Pi/2
      )
   )
end proc:

violinplot([45,7,4,345,8,456,3,2,45,444,111,34], left= 0, axes= boxed);

Isn't this plot tipped and capped as you want?


Your command

with Statistics;

should be

with(Statistics);

You are missing parentheses.

Here's a few tips to start you on the right track, although I don't know yet if your problem can be solved by Maple. It may be able to do part of it, or maybe all of it.

  1. The imaginary unit in Maple is capital I.
  2. Whenever you refer to functions such as pi, phi, and v, you need to include the arguments: pi(x), phi(x), v(x).
  3. Maple makes no meaningful distinction between partial and full derivatives; although you may be able to get the prettyprinter to display them differently. Since all your derivatives are taken with respect to x, you'll be better off just thinking of them as full derivatives.
  4. The solve command does not solve differential equations. The dsolve command is for that. For this problem, you may need to use the DEtools package.

If you replace all three occurences of sum with add, then your function will work. However, it can be improved in several ways, which I'll write about later. I just wanted to get you a minimally working version before I work further with it.

Edit: Here are some improvements:

f:= proc(h::And(even,nonnegint))
   option remember;
   local m;
   h! - add(3*thisproc(2*m)*m, m= 1..h/2-1)
end proc:

f(2):= 3:

g:= proc(n::nonnegint)
   local a,m;
   3 + 2*n - add(add(f(2*a), a= 1..iquo(m,2)), m= 1..n)
end proc:

That's definitely a bug! You can see what's going on if you change cos(2*Pi*k*x) to cos(Pi*k*x). In the former case, it seems as if exp(-2*I*Pi*x) is being erroneously simplified to 1. Here's a workaround: Change cos(2*Pi*k*x) to cos(A*Pi*k*x), evaluate the symbolic sum, and then eval the resulting hypergeometric expression at A= 2.

I'll submit an official bug report.

There are certain basic evaluations, mostly involving simple arithmetic, that are always done, even when you use the usual methods to delay evaluation. These are called "automatic simplifications," and you can read about them at ?ProgrammingGuide,Chapter03. There are two tricks that can be used to prevent or delay these automatic simplifications. They both involve encapsulating a number with backquotes (``), but they are very different.

The first method puts the numbers in the quotes. This is analogous to the convert(..., symbol) that Markiyan describes below (but is less to type). To force evaluation, i.e. to remove the effect of the quotes, one must apply parse to the quoted subparts. There are a number of subtleties to parse  that I won't go into here. This method is more of a "trick" that is used for display purposes, often in plots. I wouldn't call it an "official" method for preventing evaluation which one would use programmatically, but it can be used if you like the way it displays on screen.

The second and more robust method for preventing or delaying automatic simplification is to encapsulate the numbers as unevaluated function calls, using `` as the function. You force evaluation of this form simply by using expand.

 

restart;

ex:= (3*x^2-3*y^2)/(x-y);

(3*x^2-3*y^2)/(x-y)

ex1:= subs([x= `5`, y= `2`], ex);

(-3*`2`^2+3*`5`^2)/(`5`-`2`)

evalindets(ex1, name, parse);

21

ex2:= subs([x= ``(5), y= ``(2)], ex);

(3*``(5)^2-3*``(2)^2)/(``(5)-``(2))

expand(ex2);

21

 

Download eval_exmp.mw

Solving for a variable does not assign the value of that variable. You may assign it if you want, but that is often undesirable because it affects all expressions using that variable.. The usual method is to use the solution with the eval command to evaluate an expression at the solution. I hope this example will illustrate this concept for you:

 

f1:= randpoly(iDS, degree= 2);

97*iDS^2-73*iDS-4

f2:= randpoly(iDS, degree= 2);

-83*iDS^2-10*iDS+62

M:= < < f2 > >; # a 1-element matrix.

M := Matrix(1, 1, {(1, 1) = -83*iDS^2-10*iDS+62})

sol:= solve(f1, {iDS});

{iDS = 73/194+(1/194)*6881^(1/2)}, {iDS = 73/194-(1/194)*6881^(1/2)}

sol[1];

{iDS = 73/194+(1/194)*6881^(1/2)}

eval(M[1,1], sol[1]);

-83*(73/194+(1/194)*6881^(1/2))^2+5649/97-(5/97)*6881^(1/2)

evalf(%);

.32537173926081

 

 Don't hesistate to ask if you need more explanation.

Download eval_exmp.mw

Here are three ways based on the idea that what you want is the remainder from dividing by x[n]^6:

  1. algsubs(x[n]^6= 0, prd);
  2. simplify(prd, {x[n]^6 = 0});
  3. evala(Rem(prd, x[n]^6, x[n]));

And here are two ways based on simple truncation:

  1. convert(series(prd, x[n], 6), polynom);
  2. add(coeff(prd, x[n], k)*x[n]^k, k= 0..5);

All five methods give identical results.

You could rotate a semicircle of radius r around the x-axis:

restart;
f:= x-> sqrt(r^2-x^2):
int(Pi*f(x)^2, x= -r..r);
                            4     3
                            - Pi r
                            3    

Regarding your question about the tickmarks: Each tick on the horizontal axis of the plot that you posted represents a separate power of 10, so it is appropriate that those ticks are linearly spaced. The ticks on the vertical axis of that plot that are logarithmically spaced. If you use a narrower range on the horizontal axis, you will get logarithmic ticks there also. You can achieve much finer control of the tickmarks by using some options to the plot command (see ?plot,tickmarks), but this can quickly get excessively complicated.

And to get the Moore-Penrose generalized inverse of a singular square matrix, use LinearAlgebra:-MatrixInverse with the method= pseudo option. For example,

A:= <<0,0>|<1,0>>;
                             [0  1]
                             [      ]
                             [0  0]
LinearAlgebra:-MatrixInverse(A, method= pseudo);
                             [0  0]
                             [      ]
                             [1  0]

If floating-point answers are acceptable, you can use the Statistics package:

Statistics:-Mean(A);
Statistics:-Variance(A);

or, the same thing with fancier syntax:

use Statistics in [Mean,Variance](A) end use;

Try convert(%, sin) or convert(%, cos). Does that give you what you want? If not, could you state more explicitly what is the pattern that you want?

First 386 387 388 389 390 391 392 Page 388 of 395