Adri van der Meer

Adri vanderMeer

1400 Reputation

19 Badges

20 years, 137 days
University of Twente (retired)
Enschede, Netherlands

My "website" consists of a Maple Manual in Dutch

MaplePrimes Activity


These are answers submitted by Adri van der Meer

Firstly: TABLE (capitals) is in the list of undocumented names that are reserved for internal use. So use table. Now you can simply assign the remaining entries, and thus add these to the table:

M[2]:=table([e = {2,3}, a = 5, c = 1]):
M[2][b]:={3,4}: M[2][d]:=4:
seq(M[2][i], i=[a,b,c,d,e]);

  • Use Vector(..) and Matrix(..), not vector and matrix
  • What is a1h := Generate; meant to do?
  • the last statement in the loop is meant to fill the nth row of result: that is result[n,1..3], I suppose with the vector mmT, not mT.
  • The Matrices M, m and mm do not depend on n, so the rows of result will all be the same.

 

  • the right hand side of the equation is ambiguous. Do you mean sin(x1)/exp(x1)?
  • you use V as a function of x1 and x2, but x2 doesn't appear in the rest of the equation. So you cannot expect x2 to appear as a variable in the solution
  • you have ab where a*b is meant

With V a function of only x1, you have an ODE, which can be solved by

DE := (a*b+(a*sin(x1)^2-(c*cos(x1))^2)*diff(V(x1),x1)) = -sin(x1)/exp(x1);
dsolve( {DE,V(0)=0}, V(x1) );

There is an integral in the solution, but if you assign values to the parameters you can plot or use evalf to approximate specific values of V.

In your txt-file there are some lines of text, a $-sign and one more line of text before the data, These are separated by semicolons. It surprises me a little that the Import Data Assistent doesn't work properly.

So you may try

fn := "test.txt":
c := "start": Heading := " ":
while c<>"$" do
  c :=readline(fn):
  Heading := StringTools:-Join([Heading,c])
end do:
Heading := StringTools:-Join([Heading,readline(fn)]); #one extra comment line
L := NULL:
c := readline(fn):
while not(c=0) do
  L := L,[parse( StringTools:-SubstituteAll(c,";",",") )]:
  c := readline(fn)
end do:
A := Matrix([L]);

Perhaps the answers on this question helps.

To create the (n+1)×(m+1)-matrix from a n×m-matrix, you can make a procedure. I suppose that the dimensions are not too large, so I did not try to make it efficient:

NewMatrix := proc(A)
  local B,i,j, n,m:
  n,m := LinearAlgebra:-Dimension(A);
  B := Matrix(n+1,m+1);
  for j to m do B[1,j+1] := -add(A[i,j],i=1..n) end do;
  for i to n do B[i+1,1] := -add( A[i,j],j=1..m) end do;
  B[1,1] := -add(B[1,j],j=2..m+1):
  B[2..n+1,2..m+1] := A;
  B;
end proc:
 
NewMatrix( <a,b;c,d;e,f> );

(edited: correction in line 7)

The solution is exactly in the format to use in an eval- or subs-command:

s := {x=5,y=6,z=1}:
v := eval( <x,y,z>, s );

The errormessage is

Error, (in newton_raphson) cannot determine if this expression is true or false: 
0.5000000000e-5 < BesselJ(0, 2)/BesselJ(1, 2)

This means that  f and D(f) are not evaluated to numeric values.
Of course you can insert some evalf(...) in the procedure, but it is easier to call it with floating point arguments:

 low:=-5.:
up:=5.:
step:=1.:
dp:=5.:

Compare the different results of

 BesselJ(0,2);
                         BesselJ(0, 2)
BesselJ(0,2.);
                          0.2238907791

The naive method: solve a system of (linear) equations, wil work here:

restart;
with(LinearAlgebra):
n := 5:
f := x -> add( a[i]*x^i, i=0..n ):
X := RandomVector(6):
Y := RandomVector(6):
eqns := {seq( f(X[i])=Y[i], i=1..6 )}:
s := solve( eqns, {seq( a[i], i=0..5)} ):
pol := unapply( subs(s,f(x)), x );

 InterpolationPol.mw

My strategy is as follows

(1) Give a ?tracelast command immediately after the errormessage. Sometimes this gives you sufficient information about where the error occurs.

(2) Insert some ?print commands to display strategic variables, especially in loops.

(3) If the error occurs in a procedure, you can use ?trace

A boundaty condition like dui/de(-500,t) = 0 must be entered as

D[1](ui)(-500,t) = 0

Use a ?slider to vary the horizontal range of the plot. I suppose the example in the help page is sufficient for your purpose.

@dhonkabulo I'm rather sure that Carl Love is right. You can check this by typing simply

a;

and look if a plot appears.
If you don't want to choose another name for this plot, or to unassign a, you can do:

plots:-textplot([x,y, typeset(` a`[0]=1)], align = above);

(don't forget the extra space between the backqoutes)

I suppose that Maple cannot make a (smooth?) density function for an empirical distribution.
You can plot the CDF:

plot(CDF(X,t), t=-20..40 );

or a histogram:

 Histogram(P);
First 13 14 15 16 17 18 19 Last Page 15 of 27