acer

31285 Reputation

29 Badges

19 years, 108 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

This is the sort of thing that should be in the Tasks section of the help system.

The closest Task I can find to this is ?Task,EquationOfLineBetweenTwo2DPoints  . And that one is done using the geometry package, so can't serve to instruct anyone in the underlying mathematics. Which is a slight shame.

This below can also be done using `.` for DotProduct and ^%T for Transpose. Or VectorCalculus could be used. I'm not sure which is clearer.

with(LinearAlgebra):
r0 := <0, 4/3, - 5/3>:
 
p1,b1 := <3,1,-1>, 3:
DotProduct(Transpose(<x,y,z>), p1) = b1;
                               3 x + y - z = 3
# zero, only if r0 lies on plane 1
DotProduct(Transpose(p1), r0) - b1;
                                      0
p2,b2 := <1,2,4>, -4:
DotProduct(Transpose(<x,y,z>), p2) = b2;
                             x + 2 y + 4 z = -4
# zero, only if r0 lies on plane 2
DotProduct(Transpose(p2), r0) - b2;
                                      0
# line perpendicular to (p1 and p2) the normals of planes 1 and 2
L := CrossProduct(p1, p2):

# zero, only if L is perpendicular to p1 the normal of plane 1
DotProduct(Transpose(p1), L);
                                      0
# zero, only if L is perpendicular to p2 the normal of plane 2
DotProduct(Transpose(p2), L);
                                      0
# parametric Vector form, one form of the answer
Lpara := r0 + t*L:

# zero, only if any value of parameter t in Lpara makes point lie on plane 1
DotProduct(Transpose(p1), Lpara) - b1;
                                      0
# zero, only if any value of parameter t in Lpara makes point lie on plane 2
DotProduct(Transpose(p2), Lpara) - b2;
                                      0
# parametric form (using x,y, and z notation)
DotProduct(Transpose(<x,y,z>), Lpara, conjugate=false);
                            /4       \     /  5      \
                    6 t x + |- - 13 t| y + |- - + 5 t| z
                            \3       /     \  3      /

acer

The original posting is opaque to me. I went back a few times to try and figure it out.

I didn't understand what M, N, Q and V were supposed to be. There are referenced in the code, but not defined. Are they tables of arrays? Even the purpose of W is not fully clear.

I also didn't understand what was being requested, in the sense of display and columns.

There were a few sentences that I couldn't parse. Eg, "I'm trying to print a nice looking array (6 columns with various numbers of rows) from an array that storing the data with 5 indices." And, "I can print P as a table, but I want it to print with i for the columns 1..6 and the column can just fill up with the entries. "

acer

Do you mean something other than like this?

> den:=a*u*Dirac(u)+b*u*u*Dirac(u)+c*u^(3/2)*Dirac(u)+d*cos(v+Pi/6)*Dirac(v):

> simplify(den);
                                  1/2
                              1/2 3    d Dirac(v)

acer

Something like this?

Ez:=(sigma*z*int(r/((r^2+z^2)^(3/2)),r=0..a))/(2*epsilon0) assuming z::real;
E:=unapply(eval(Ez,[epsilon0=8.854e-12,sigma=1e-6,a=0.1]),z);
plot(E,-5*0.1..5*0.1);
plot(eval(Ez,[epsilon0=8.854e-12,sigma=1e-6,a=0.1]),z=-5*0.1..5*0.1);

acer

That's pretty sophisticated, and wouldn't be easy with only a basic knowledge.

Have a look at the help-page  ?IterativeSolver  which describes how a conjugate gradient solver may be accessed by calling the LinearAlgebra:-LinearSolve routine.

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

First 306 307 308 309 310 311 312 Last Page 308 of 326