acer

31819 Reputation

29 Badges

19 years, 179 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

What version of Maple and operating system do you have?

Here's what I get, with Maple 11.02 (Linux),

> v:=Vector([v1, v2, v3, v4, v5]);
                                        [v1]
                                        [  ]
                                        [v2]
                                        [  ]
                                   v := [v3]
                                        [  ]
                                        [v4]
                                        [  ]
                                        [v5]
 
> CodeGeneration[C](v);
cg[0] = v1;
cg[1] = v2;
cg[2] = v3;
cg[3] = v4;
cg[4] = v5;
What precisely were your commands?

acer

You can generate the filenames in a loop as follows, using concatenation.

There are a variety of utilities that can be used to write the data to the file. One such is writedata, but you should also be able to use fopen, fprintf, and fclose directly.

M := matrix([[1.,2.,3.],[4.,5.,6.],[7.,8.,9.]]);

for i to 3 do
  fname := "basename"||i||".txt";
  writedata(fname,M);
  fclose(fname);
end do;

For Matrix (as opposed to matrix) objects you could look at the ExportMatrix routine.

acer

The Statistics:-NonlinearFit routine can achieve this, setting up and solving it as a least squares problem.

Do you just need the answer, or is it a homework exercise for which you are requested to submit all the details?

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

First 311 312 313 314 315 316 317 Last Page 313 of 330