acer

32470 Reputation

29 Badges

20 years, 5 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

y := <2,4,8>;
x := <1,4,6>;

sol := Statistics:-NonlinearFit(p*t + q, x, y, t);

Alternatively,

sol2 := CurveFitting:-LeastSquares(x,y,t);
evalf(sol2);

You can then plot them all,

p1:=plots:-pointplot([seq([x[i],y[i]],i=1..3)]):
p2:=plot(sol,t=0..7):
p3 := plot(sol2,t=0..7):
plots:-display([p1,p2,p3]);

acer

The %n values that you see are placeholders for common subexpressions.

That is to say, subexpressions which appear more than once in the output. With them extracted out and displayed in this way the whole result is supposed to be easier to view and understand.

See this blog entry, for some fun details. Also see the labelling and labelwidth entries in the ?interface help-page.

You may see them used in the Classic GUI and the commandline (TTY) interface, but not at present in the Standard GUI. (That's a shame, about the Standard GUI, on the same level as the inability to select and get context-menus for subexpressions in output.)

acer

Floating-point numbers are approximations of real numbers.

The number of trailing digits (or, here, zeros) can indicate how much accuracy such an approximation has.

Take 0.75, for example. We don't know how accurate it is beyond the second decimal place. It might be a measurement (or approximation) which is off by an amount something less than (say) 0.005. This may be termed as an amount of five ulps (units in the last place).

If you enter evalf(3/4) in Maple then it will use its working precision enviroment variable, which is named Digits, to specify how many trailing zeros to add on to the floating-point result. That makes sense, since 3 and 4 are exact values, so one gets the best approximation possible at the current working precision. The default value of Digits is 10. Increase Digits to 20, and repeat, and you would see more zeros.

The behaviour for the computation 3/(4.) is a trickier to rationalize. One might imagine that, since 4. is only known to one place, then the result should not be expressed as if it were known more accurately than each of the inputs.

There are two environments for doing more careful handling of accuracy in floating-point computations in Maple. One is the ScientificErrorAnalysis package, and the other is the Tolerances package.

You might be interested in the help-pages ?numericrefs , ?numerics , and ?evalf,details . While good reading, there are certain basic aspects of Maple's numeric model (such as guranteed accuracy) which these help-pages don't appear to cover directly.

acer

Some simplification might do it. But sometimes that can involve more than just a simple call to simplify.

Maybe it the expressions are not too large you could lprint them and post them here.

acer

Where does this Maps package come from?

What version of Maple are you using? Do you know for which version of Maple this package was developed?

Is there a maple.ind file that accompanies the maple.lib file that you have in directory c:\\maps ?

What command did you issue, in order to get that error message? Was it, with(Maps) ?

acer

Are you looking for an effect that is something like this, where the fit is calculated as usual but the plot displays both the fitted curve, the data points, and something that connects them?

N:=50:
X:=LinearAlgebra:-RandomVector(N,generator=0.0..6.0):
E:=LinearAlgebra:-RandomVector(N,generator=-5.0..5.0):
Y:=Vector(N,(i)->eval(6.5-4.5*v+exp(0.75*v),v=X[i])+E[i]):
S := Statistics:-NonlinearFit(a+b*v+exp(c*v), X, Y, v ):
with(plots):
p1 := plot([seq([X[i],Y[i]],i=1..op(1,X))],style=point,
           color=COLOR(RGB,0.0,0.3,0.0),symbol=circle):
p2 := plot(S,v=0.0..6.0):
for i from 1 to op(1,X) do
  a[i] := plottools:-arrow([X[i],eval(S,v=X[i])],[X[i],Y[i]],
                           .01,.01,.0,
                           color=COLOR(RGB,0.0,0.3,0.0));
end do:
display([p1,p2,seq(a[i],i=1..op(1,X))]);

You can get similar effects using Statistics:-ScatterPlot (with its 'fit' option) alongside Statistics:-ErrorPlot. But it's not as nice as it could be, because the fitting function S is needed to produce the ErrorPlot. That means an unnecessary duplication of the calculation is done. (And if one has to go to that trouble, then one might as well use the 'output'  options of NonlinearFit and so request both 'residuals' and 'leastsquaresfunction' all at once.)

R:=Statistics:-ScatterPlot(X, Y, fit = [a+b*v+exp(c*v), v],
                           color=red):

Q:=Statistics:-ErrorPlot([<seq(eval(S,v=X[i]),i=1..op(1,X))>],
          xerrors=Vector(op(1,X)),
          yerrors=<seq(eval(S,v=X[i])-Y[i],i=1..op(1,X))>,
          xcoords=[seq(X[i],i=1..op(1,X))]):
display([R,Q]);

Also I'm not sure that ErrorPlot is really better here, since as given above the second plot seems to muddle the idea that the residuals each have a sign.

acer

I believe that the error message, "Error, system calls are disabled" occurs when trying to use wrapper-generating external calling while system/ssystem calls are disabled. At least, that's what I see after starting Maple 11.02 with the -z option.

On the other hand, if my working directory is not writable by me and I try a define_external() call with the WRAPPER option, then I see an error message like, "Error, could not create wrapper source file, mwrap_foo.c".

Try issuing the currentdir() command, and checking whether you have permission to write to files there. If this turns out to be the cause then you could create a new folder (for which you do have write permissions) and then use Maple's currentdir() command to make it the current working directory for your Maple session.

acer

You're using f/D(f) as the correction term. But you need both of those operators f and D(f) to actually be evaluated at the point x.

Also, you can't have f be a parameter of procedure NR1 as well as a local variable. I deleted it as the latter.

> NR1:= proc(f,x0,N)
> local x,k:
>  x := x0:
>  for k to N do:
>    x := x-f(x)/D(f)(x)
>  end do:
>   evalf(x):
>  end proc:

> f:= x-> x^2-2:

> NR1(f,1,10);
                                  1.414213562

acer

Maple 11.02,

> restart:
> kernelopts(version);
             Maple 11.02, X86 64 LINUX, Nov 9 2007 Build ID 330022

> Statistics:-Sample(Statistics:-RandomVariable(Poisson(10^7)),1);
Error, (in Statistics:-Sample) NE_REAL_ARG_GT:
  On entry, rlamda must not be greater than 1.0e6: rlamda = 1e+07.

> UseHardwareFloats:=false:
> Statistics:-Sample(Statistics:-RandomVariable(Poisson(10^7)),1);
                                [            7]
                                [0.9999330 10 ]

> restart:
> Digits:=trunc(evalhf(Digits))+1:

> Statistics:-Sample(Statistics:-RandomVariable(Poisson(10^7)),1);
                                [            7]
                                [0.9999993 10 ]
> rtable_options(%,'datatype');
                                   anything

> Statistics:-Sample(Statistics:-RandomVariable(Poisson(1.0*10^7)),1);
                                [            7]
                                [0.9998593 10 ]
 
> rtable_options(%,'datatype');
                                   anything
 

I'm a little surprised that the results don't have more than seven decimal digits of information.

acer

Do you really want a matrix "square root", or do you perhaps want a Cholesky decomposition?

By that I mean, do you want Matrix S such that S.S=M for Matrix M? Or do you perhaps want Matrix L such that L.Transpose(L)=M for symmetric positive-definite Matrix M? I ask simply because the latter is more common, in general practice, and we don't know your original motivating problem.

As for the difficulty of computing the general symbolic "square root", compare the eigenvalues of,

Matrix(3,3,[[a,b,c],[d,e,f],[0,0,i]]);

with those of,

Matrix(3,3,[[a,b,c],[d,e,f],[0,h,i]]);

On the chance that a Cholesky decomposition of a symmetric Matrix would do, and assuming also that you data will be purely real,

> restart:
> with(LinearAlgebra):
> M := Matrix(3,3,[[a,b,c],[b,e,f],[c,f,i]]);
                                   [a    b    c]
                                   [           ]
                              M := [b    e    f]
                                   [           ]
                                   [c    f    i]
 
> L := LUDecomposition(M,'method'='Cholesky','conjugate'=false);
        [ 1/2                                                              ]
        [a    ,                            0 ,                            0]
        [                                                                  ]
        [                            /       2\1/2                         ]
        [ b                          |e a - b |                            ]
        [---- ,                      |--------|    ,                      0]
        [ 1/2                        \   a    /                            ]
   L := [a                                                                 ]
        [                                                                  ]
        [                         /           2    2      2            \1/2]
        [ c        f a - b c      |i a e - i b  - c  e - f  a + 2 f b c|   ]
        [---- , --------------- , |------------------------------------|   ]
        [ 1/2     /       2\1/2   |                     2              |   ]
        [a        |e a - b |      \              e a - b               /   ]
        [       a |--------|                                               ]
        [         \   a    /                                               ]
 
> simplify( L.Transpose(L) - M );
                                 [0    0    0]
                                 [           ]
                                 [0    0    0]
                                 [           ]
                                 [0    0    0]

acer

You entered,

solve({100-m*qj-qI-qj-v = 0, 100-(m-1)*qj-3*qI-ld = 0}*{qj, qI});

instead of,

solve({100-m*qj-qI-qj-v = 0, 100-(m-1)*qj-3*qI-ld = 0},{qj, qI});

acer

Instead of left-clicking, right-click to get the context-sensitive menu.

Select "Browse" from the context menu that appears when you right click.

acer

It is possible to create a Vector which uses a built-in indexing function that accomplishes this. An indexing function is a smart-access mechanism for Vectors and Matrices, as well as a control on what may be assigned into the object.

This is what LinearAlgebra:-UnitVector() can produce, which Joe illustrated. The code below shows how the Vector() constructor can also produce the same objects.

> for i to 4 do
> e[i] := Vector(4,'shape'='unit'[i]);
> end do:

> e[3];
                                      [0]
                                      [ ]
                                      [0]
                                      [ ]
                                      [1]
                                      [ ]
                                      [0]

> lprint(e[2]);
Vector[column](4,{},datatype = anything,storage = empty,
order = Fortran_order, shape = [unit[2]])

On the one hand, this can be useful if the dimension is very large (>>4 say) and one wishes to keep memory allocation down. That's because such Vectors have "empty" storage, yet produce the right values whenever any element of them is accessed or used. On the other hand, it may incur a slight but measurable extra time efficiency cost to access them many times, due to the overhead of calling the indexing function for each access. That's a typical storage versus speed dichotomy.

Calling LinearAlgebra:-UnitVector() with the 'compact'=false option will produce these objects without any indexing function, and with full explicit storage.

> for i to 4 do
> e[i] := LinearAlgebra:-UnitVector(i,4,'compact'=false);
> end do:

> e[3];
                                      [0]
                                      [ ]
                                      [0]
                                      [ ]
                                      [1]
                                      [ ]
                                      [0]
 
> lprint(e[2]);
Vector[column](4,{(2) = 1},datatype = anything,
storage = rectangular,order = Fortran_order,shape = [])

That takes more memory (not really relevant for dimension 4, naturally), but access will be faster. Also, objects created in this way do not have restrictions on what might be subsequently assigned into their entries, which may or may not be important to one's tasks. I like this method.

One can also create row Vectors.

> LinearAlgebra:-UnitVector['row'](2,4,'compact'=false);
                                 [0, 1, 0, 0]

And it's also possible to create these objects with full non-empty storage as well as an indexing function. Eg,

> V := Vector(4,'shape'='unit'[3],'storage'='rectangular'):

> lprint(V);
Vector[column](4,{(3) = 1},datatype = anything,
storage = rectangular,order = Fortran_order,
shape = [unit[3]])

This is the least useful, since it takes more memory while still disallowing any assignment that disobeys the indexing function. There's not much point to having both those aspects hold for the same object.

> V[4]:=17;
Error, unit vector can only have one non-zero entry

That error message isn't as clear as it could be.

So, all in all there is a lot of flexibility. I find that the LinearAlgebra package's UnitVector provides the most straightforward way to get all the desirable functionality.

acer

You might also look at OrthogonalSeries, if you're interested in such things. I don't think that there's a cross-reference from ?orthopoly to ?OrthogonalSeries .

acer

What are your thoughts about the following example.

> restart:

> limit(1/((x-2)*(x-1)),x=1,right);
                                   -infinity
 
> limit(1/((x-2)*(x-1)),x=1,left);
                                   infinity
 
> eval(1/((x-2)*(x-1)),x=1);
Error, numeric exception: division by zero

> MyHandler := proc(operator,operands,defVal)
> WARNING("division by zero in %1 with args %2",
>         operator,operands);
> defVal
> end proc:

> NumericEventHandler(division_by_zero=MyHandler):

> eval(1/((x-2)*(x-1)),x=1);
Warning, division by zero in ^ with args
[0, -1]
                                   -infinity

acer

First 318 319 320 321 322 323 324 Last Page 320 of 337