pagan

5147 Reputation

23 Badges

17 years, 124 days

 

 

"A map that tried to pin down a sheep trail was just credible,

 but it was an optimistic map that tried to fix a the path made by the wind,

 or a path made across the grass by the shadow of flying birds."

                                                                 - _A Walk through H_, Peter Greenaway

 

MaplePrimes Activity


These are answers submitted by pagan

> f := -1/n/n1*(-n1*n*K^2+K^2*n1^2+n1*n^2*L-L*n*n1^2)^(1/2)+z;

                         2    2   2       2           2 1/2
                 (-n1 n K  + K  n1  + n1 n  L - L n n1 )
               - ------------------------------------------ + z
                                    n n1

> map(t->expand(simplify(numer(t)/sqrt(n1),symbolic))
>        /expand(denom(t)/sqrt(n1)),
>     f);

                                1/2          2 1/2
                        (n - n1)    (-L n + K )    I
                      - ---------------------------- + z
                                    1/2
                                  n1    n
 

This may be handled by convert/trigh.

For example,

> f:=exp(x*I)+exp(-x*I):

> convert(f, trig);
                                   2 cos(x)
 
> convert(f, trigh);
                                  sinh(2 I x)
                                  -----------
                                   sinh(x I)

There is a command which rotates plots. As an example

Gx:=.025+(x^2)/40:
p1:=plot(Gx,x=-2..2,color=blue):
plots:-display(plottools:-rotate(p1,-Pi/2),labels=[y,x]);

I didn't understand the bit about, "tangent to Fx in highest point", sorry.

In 1D Maple Notation the input D(y) (x) with a space will get parsed as (D(y))(x) the application of the differentiated operator D(y) at x. In 2D Math it gets parsed as D(y)*x, whatever that might mean.

One solution is to use 2D Math input and be really careful about spaces. Another is to use 1D Maple Notation for input. Either input mode can be selected as a preference under the Display tab of the page Tools -> Options from the top menu bar.

I get the expected sequence, in Maple 12. Do you get that answer above, even after a restart? If so, then with which version of Maple and on what platform?

What happens if you use Sum instead of 'sum' for the inert form of sum?

N_unr:=Sum((n_0-2+u)!/(u!*(n_0-2)!),u=0..n_P-2):
N2:=Sum((2*u2-D_n)!/(u2!*(u2-D_n)!),u2=D_n..min(u,n_max-1)):
N:=Sum(N_unr-piecewise(u<D_n,0,N2),u=0..n_P-2):
value(eval(N,{n_0=3,n_P=4,n_max=4}));

eval(%,D_n=1);
evalc(simplify(%));

Could it be potentially less confusing if the summation index in N_unr were u1 instead of u, since u is used for N? I mean, provided that is how you meant N_unr, with no occurence of N's summation index in it. I find it hard to tell what you intended.

Replace the square brackets that you are using as delimiters with round brackets. Ie, replace

[1-(x[1]-1)^2]

with

(1-(x[1]-1)^2)

and so on.

This issue comes up a quite often, about once every week or so in the past month. The default setting in the Standard interface might be too low. And it could be a useful FAQ. And there could be a GUI Tools->Option->Display option to control it.

In line with Alec's response, try it with,

C := Matrix(B);

instead of,

C := convert(B,matrix);

Do you really need to display the results in a spreadsheet, to store them in a table (since you appear to know the size at the start), and to use a global?

You could have CalculateDT create a Vector(6), or Vector[row](6), or Matrix(1,6), assign that to a local variable of CalculateDT. Then CalculateDT could return that variable on its last line.

You could then assign the results, when calling CalculateDT.

result := CalculateDT(10);

Viewing a Vector or Matrix is quite simple, and they print nicely and also have a popup viewer. To print large ones issue kernelopts(rtablesize=100) once at the start of the session. 

You can print Vector or table contents easily, to scientific or other formats using printf(). So perhaps the spreadsheet is not needed.

> V := Vector[row]([56.78789341,607.11112323]);
                       V := [56.78789341, 607.11112323]

> seq(printf("%e  ",V[i]),i=1..2),printf("\n");

5.678789e+01  6.071111e+02

> seq(printf("%f  ",V[i]),i=1..2),printf("\n");

56.787893  607.111123

> seq(printf("%g  ",V[i]),i=1..2),printf("\n");

56.7879  607.111

> t := table([(1)=56.78789341,(2)=607.11112323]):

> seq(printf("%e  ",t[i]),i=1..2),printf("\n");

5.678789e+01  6.071111e+02  

In that double-loop near the end, the code accesses f for values of its indices which haven't been assigned.

The code is messy, with that global f, the concatenating looped creation of L, etc. It's hard to figure out what you intended.

Did you perhaps intend that double-loop to start with,

  for i from 1 to N do for j from 1 to N-i+1 do

instead of

  for i from 1 to N do for j from 1 to i do

Or, how about this loop below? It always assigns to f[N+1], which doesn't look useful (or intended). Maybe that's why f's first index doesn't go as high as you expected?

  for i from 1 to N+1 do f[N+1] := [seq(max(L[N+1, i]-X, 0), i = 1 .. N+1)] end do;

Perhaps you intended that to instead be

  for i from 1 to N+1 do f[i] := [seq(max(L[N+1, i]-X, 0), i = 1 .. N+1)] end do;

Both of these edits, done separately, allow the code to run. If I had to guess, I would say that the second edit is the one that you really wanted (and not the first above).

You should add a check on the number of times through the loop to that while condition, so that it cannot run forever. Something like,

  counter := 0;
  while tol < e do and counter < maxsteps
...
  counter := counter + 1;
...
  end do;

You need evalf calls, so that the less-than comparison can be done simply (evalb). There should be an abs() around the formula for `e`, so that it doesn't return wrongly as soon as x2 lies on the other side of the true root. And you need to update x1 with the value of x2, each time through the loop.

> cuberootkj := proc (m, n)
> local e, tol, x0, x1, x2, maxsteps, counter;
> tol := 1/200000;
> e := 1;  x1 := m;  x0 := n;
> while tol < e do
> x2 := evalf( (2/3)*x1+(1/3)*x0/x1^2 );
> x1 := x2;
> e := abs( x2-surd(evalf(x0), 3) );
> end do;
> x2;
> end proc:

> cuberootkj(30,10);
                                  2.154434694
 
> cuberootkj(-30,10);
                                  2.154435305

Can the CurveFitting:-ArrayInterpolation routine be used here?

This example from that routine's help page looks interesting.

First, the function (unknown).

f := (i,j) -> (3-sin(i))^2-(3-j)^2:
plot3d(f,0..10,0..10,axes=normal);

Now, some grid points.

x := Array([0,1.5,3.5,5,6,8,9]):
y := Array([0,3,5,6,6.5,7.5]):

And the z-values for those grid points.

z := Matrix(7,6,(a,b)->evalf(f(x[a],y[b]))):

This would be all that is known. The (x,y) points and their heights z are known. Here is a plot of those points.

plots:-pointplot3d([seq(seq([x[i],y[j],z[i,j]],j=1..6),i=1..7)],axes=boxed,symbol=sphere);

But function f is not known, and the hope is that piecewise interpolation will approximate it well "inside" the grid. (I write "piecewise", since higher order interpolation is expensive and yet can still produce unsatisfactory results. So low degree splines using only a few neighboring points get used.)

Set up a new, finer grid.

a1 := Matrix(50,50,(i,j)->i/5):
a2 := Matrix(50,50,(i,j)->j/5):
A := ArrayTools[Concatenate](3,a1,a2):

And now try it out.

with(CurveFitting):

B := ArrayInterpolation([x,y],z,A,method=linear):
plots:-matrixplot(Matrix(B),axes=normal);

B := ArrayInterpolation([x,y],z,A,method=spline):
plots:-matrixplot(Matrix(B),axes=normal);

I guess icing would be to produce something like those last matrixplots, but with the right values along the x- and y-axes.

The idea is that you would specify the new (x,y) points at which you wanted the interpolation to be done. Those points be supplied like `A` is above. For example

> mypoints:=Array(1..2,1..2,1..2,[[[3,7],[3.5,7.5]],[[3,7.5],[3.5,7]]]):

> ArrayInterpolation([x,y],z,mypoints,method=spline);
                [-7.55409566433689861    -9.02225175999981843]
                [                                            ]
                [-11.7212152290612579    -4.85513219478244196]

> seq(seq([mypoints[i,j,1],mypoints[i,j,2]],i=1..2),j=1..2);
                   [3, 7], [3, 7.5], [3.5, 7.5], [3.5, 7]

>map(p->f(op(evalf(p))),[%]);
           [-7.826805191, -12.07680519, -9.02225176, -4.77225176]

Notice that, of the above points in `mypoints`, only [3.5,7.5] is in the original grid specified by coordinate lists `x` `y`. That's why its interpolated value matches f(3.5,7.5) "exactly".

Some improvement can be had, for this example, by increasing the degree of the piecewise splines.

> ArrayInterpolation([x,y],z,mypoints,method=spline,degree=5);
                [-7.65741254250933778    -9.02225175999996587]
                [                                            ]
                [-11.9074125420541126    -4.77225175999997564]
 
> ArrayInterpolation([x,y],z,mypoints,method=spline,degree=7);
                [-7.84409825449225551    -9.02225176000004403]
                [                                            ]
                [-12.0940982541189186    -4.77225176000005025]

I saw something like this in another thread here:

> pdiff := (f,x)->thaw(value(subs(x=freeze(x),Diff(f,x)))):
> L := 0.5*m*diff(x(t),t)^2 - mg*x(t):
> diff(pdiff(L, diff(x(t), t)), t) = pdiff(L, x(t));
                                  / 2      \
                                  |d       |
                            1.0 m |--- x(t)| = -mg
                                  |  2     |
                                  \dt      /
Alternatively, you could probably frontend() the diff() call, to differentiate L w.r.t. xdot.

Were you looking for the exact value, or a floating-point approximation? In Maple 12,

> g:=exp(1/x)+x^3:
> Optimization:-Minimize(g,x=0.5..2);
               [3.71551699771343946, [x = 0.980508996132251842]]

> solve({diff(exp(1/x)+x^3,x),x>1/2,x<2},x);
                                          1
                           {x = 1/4 --------------}
                                              1/4
                                             3
                                    LambertW(----)
                                              4
 
> evalf(%);
                              {x = 0.9805089962}
My Maple 10 returned unevaluated, using `minimize`. Which minor version was it? (Ie. what does kernelopts(version) return?)
First 43 44 45 46 47 48 Page 45 of 48