tomleslie

13876 Reputation

20 Badges

15 years, 168 days

MaplePrimes Activity


These are answers submitted by tomleslie

see the attached

restart;
Explore( plot( x^2*sin(a*x),
               x=-2*Pi..2*Pi
             ),
         animate=true,
         autorun=true,
         loop=true,
         parameters=[ a=[ seq(j, j=-15..-7),
                          seq(j, j=7..15)
                        ]
                    ]
      );

 

Download animExplore.mw

between your code and Maple's in-built CenterOfMass() command gives the same answer - alwaysa good sign!

See the attached

 

  restart;
#
# Using Maple's in-built CenterOfMass calculator
#
  with(Student[MultivariateCalculus]):
  rho:= (r, theta, phi)-> ln(r^2+theta^2+phi^2+1):
  CenterOfMass( rho(r, theta, phi),
                r=0..2,
                theta=0..2*Pi,
                phi=0..Pi,
                coordinates=spherical[r, phi, theta],
                output=integral);
  xbar, ybar, zbar:=evalf(%);

(Int(Int(Int(sin(phi)^2*cos(theta)*r^3*ln(phi^2+r^2+theta^2+1), r = 0 .. 2), theta = 0 .. 2*Pi), phi = 0 .. Pi))/(Int(Int(Int(ln(phi^2+r^2+theta^2+1)*r^2*sin(phi), r = 0 .. 2), theta = 0 .. 2*Pi), phi = 0 .. Pi)), (Int(Int(Int(sin(phi)^2*sin(theta)*r^3*ln(phi^2+r^2+theta^2+1), r = 0 .. 2), theta = 0 .. 2*Pi), phi = 0 .. Pi))/(Int(Int(Int(ln(phi^2+r^2+theta^2+1)*r^2*sin(phi), r = 0 .. 2), theta = 0 .. 2*Pi), phi = 0 .. Pi)), (Int(Int(Int(cos(phi)*r^3*ln(phi^2+r^2+theta^2+1)*sin(phi), r = 0 .. 2), theta = 0 .. 2*Pi), phi = 0 .. Pi))/(Int(Int(Int(ln(phi^2+r^2+theta^2+1)*r^2*sin(phi), r = 0 .. 2), theta = 0 .. 2*Pi), phi = 0 .. Pi))

 

-0.6221995247e-3, -.1577029946, -0.4922726106e-1

(1)

#
# Cut/paste of OP's code
#
  p:=(r,theta,varphi)->ln(r^2 + theta^2+ varphi^2+1):
  m:= int( p(r,theta,varphi)*r^2*sin(varphi),
           r=0..2,
           theta=0..2*Pi,
           varphi=0..Pi,
           numeric = true
         ):
  m_x:=int( p(r,theta,varphi)*r*sin(varphi)*cos(theta)*r^2*sin(varphi),
            r=0..2,
            theta=0..2*Pi,
            varphi=0..Pi,
            numeric = true
          ):
  m_y:=int( p(r,theta,varphi)*r*sin(varphi)*sin(theta)*r^2*sin(varphi),
            r=0..2,
            theta=0..2*Pi,
            varphi=0..Pi,
            numeric = true
          ):
  m_z:=int( p(r,theta,varphi)*r*cos(varphi)*r^2*sin(varphi),
            r=0..2,
            theta=0..2*Pi,
            varphi=0..Pi,
            numeric = true
          ):
  x_bar:=m_x/m;
  y_bar:=m_y/m;
  z_bar:=m_z/m;
                     

-0.6221995247e-3

 

-.1577029946

 

-0.4922726106e-1

(2)

 


 

Download nassCentre.mw

see the attached

 

  restart:
  interface(rtablesize=20):
  poly:=x^4+3*x^3+x^2+2*x+1:
  f:= (p,c)-> Matrix
              ( [ seq
                  ( [ 0$j,
                      ListTools:-Reverse([coeffs(p)])[],
                      0$(c-degree(p)-1-j)
                    ],
                    j=0..c-degree(p)-1
                  )
                ]
            ):
  f(poly, 5);
  f(poly, 10);
  f(poly, 20);

Vector[row](5, {(1) = 1, (2) = 2, (3) = 1, (4) = 3, (5) = 1})

 

Matrix(6, 10, {(1, 1) = 1, (1, 2) = 2, (1, 3) = 1, (1, 4) = 3, (1, 5) = 1, (1, 6) = 0, (1, 7) = 0, (1, 8) = 0, (1, 9) = 0, (1, 10) = 0, (2, 1) = 0, (2, 2) = 1, (2, 3) = 2, (2, 4) = 1, (2, 5) = 3, (2, 6) = 1, (2, 7) = 0, (2, 8) = 0, (2, 9) = 0, (2, 10) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 1, (3, 4) = 2, (3, 5) = 1, (3, 6) = 3, (3, 7) = 1, (3, 8) = 0, (3, 9) = 0, (3, 10) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 1, (4, 5) = 2, (4, 6) = 1, (4, 7) = 3, (4, 8) = 1, (4, 9) = 0, (4, 10) = 0, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = 0, (5, 5) = 1, (5, 6) = 2, (5, 7) = 1, (5, 8) = 3, (5, 9) = 1, (5, 10) = 0, (6, 1) = 0, (6, 2) = 0, (6, 3) = 0, (6, 4) = 0, (6, 5) = 0, (6, 6) = 1, (6, 7) = 2, (6, 8) = 1, (6, 9) = 3, (6, 10) = 1})

 

Matrix(%id = 18446744074374786454)

(1)

 


 

Download genMat2.mw

It is always worth reading Maple help pages

############################################################

Excerpt from the LinearAlgebra:-Norm() help page (emphasis added)

The Norm(A) command computes the infinity norm of A

Excerpt from the VectorCalculus:-Norm() help page (emphasis added)

The Norm(v, p) command computes the p-norm of the Vector or vector field v. If p is omitted, it defaults to 2.

So the "default" caclulation will always be different.

##############################################################

Now you can get the same result from both packages

LinearAlgebra:-Norm(v,  p), and

VectorCalculus:-Norm(v, p)

will return the same answers, given the same 'v' and  'p' - you just have to know which 'norm' (ie p-value) you want!

As Carl has already noted, the only "commonly-used" values for the the 'p' in a p-norm are 0,1,2,infinity - but, if you feel like a bit of experimentation, both

LinearAlgebra:-Norm(<3,4>,  37.5), and

VectorCalculus:-Norm(<3,4>,  37.5)

will return the same answer - although what the 37.5-norm of a vector actually means is beyond me (even if it is "defined")

I have no idea what this worksheet is trying to achieve!!

If I tidy up this worksheet a little, then it is simple to confirm that for NN=2, most of the time (> 99%) is taken up in computing the necessary (2^3)^3= 512 triple integrals. Since these integrals always evaluate to either 0 or Pi(-3/2), there seems to be a fair amount of redundant calculation here.

With NN=3, there will be (3^3)^3= 19683 such triple integrals and with NN=4, there will be (4^3)^3= 2621444 - so this problem really does not scale well

I'd be trying to think of a better algorithm, which does scale.

See the attached

  restart;
  NN := 2:
  nu := 1:
  M1 := NN:
  M2 := NN:
  M3 := NN:

  for k1 from 0 while k1 <= M1-1 do
      for k2 from 0 while k2 <= M2-1 do
          for k3 from 0 while k3 <= M3-1 do
              SGP[M3*(M2*k1+k2)+k3+1] := simplify(add((-1)^(k1-i1)*GAMMA(k1+i1+2*nu)*x^i1*(add((-1)^(k2-i2)*GAMMA(k2+i2+2*nu)*y^i2*(add((-1)^(k3-i3)*GAMMA(k3+i3+2*nu)*z^i3/(GAMMA(i3+nu+1/2)*factorial(k3-i3)*factorial(i3)), i3 = 0 .. k3))/(GAMMA(i2+nu+1/2)*factorial(k2-i2)*factorial(i2)), i2 = 0 .. k2))/(GAMMA(i1+nu+1/2)*factorial(k1-i1)*factorial(i1)), i1 = 0 .. k1))
          end do;
      end do;
  end do;

#
# Check the entries in table SGP (idle curiosity!)
#
  entries(SGP, 'nolist');

8/Pi^(3/2), (-16+32*z)/Pi^(3/2), (-16+32*y)/Pi^(3/2), 128*(-1/2+y)*(z-1/2)/Pi^(3/2), (-16+32*x)/Pi^(3/2), 128*(-1/2+x)*(z-1/2)/Pi^(3/2), 128*(-1/2+x)*(-1/2+y)/Pi^(3/2), 64*(-1+2*x)*(-1+2*z)*(-1+2*y)/Pi^(3/2)

(1)

#
# Following two quantities are defined but never used??!!
#
  SGPxyz := `<,>`(seq(seq(seq(SGP[M3*(M2*(i-1)+j-1)+k], k = 1 .. M3), j = 1 .. M2), i = 1 .. M1)):
  Lambda := `<,>`(seq(seq(seq(chi[M3*(M2*(i-1)+j-1)+k], k = 1 .. M3), j = 1 .. M2), i = 1 .. M1)):

#
# Check roughly the time for execution of this group
#
  st:=time():
  for i while i <= NN^3 do
      for j while j <= NN^3 do
          for k while k <= NN^3 do
              q[i, j, k] := int
                            ( int
                              ( int
                                ( SGP[i]*SGP[j]*SGP[k]*(-x^2+x)^(nu-1/2)*(-y^2+y)^(nu-1/2)*(-z^2+z)^(nu-1/2),
                                  z = 0 .. 1
                                ),
                                y = 0 .. 1
                              ),
                              x = 0 .. 1
                            );
          end do:
      end do:
  end do;
  t1:=time()-st;

13.541

(2)

#
# Check roughly the time for execution of this group
#
  st:=time():
  U := Matrix(NN^3, NN^3, 0):
#
# This is the group which OP says takes "forever"
#
#
# Check the entries in the table 'q'
#
  entries(q,'nolist');
#
# Hmmmm nothing too complicated - either 0 or Pi^(-3/2)
#
   for j while j <= NN^3 do
       for k while k <= NN^3 do
         #
         # Note that 'chi' has been defined nowhere in
         # this worksheet
         #
         # Changed 'sum()' to 'add()'
         #
           U[j, k] := add(chi[i1]*q[i1, j, k], i1 = 1 .. NN^3)
       end do;
   end do;
   t2:=time()-st;
   U;

0, 1/Pi^(3/2), 0, 0, 0, 1/Pi^(3/2), 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 1/Pi^(3/2), 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 1/Pi^(3/2), 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 1/Pi^(3/2), 1/Pi^(3/2), 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 1/Pi^(3/2), 0, 1/Pi^(3/2), 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 1/Pi^(3/2), 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 1/Pi^(3/2), 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 1/Pi^(3/2), 0, 1/Pi^(3/2), 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 1/Pi^(3/2), 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 1/Pi^(3/2), 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0, 1/Pi^(3/2), 0, 0, 0, 0, 0, 0, 0, 0

 

t2 := 0.31e-1

 

Matrix(%id = 18446744074620481398)

(3)

#
# Quick way to generate the above matrix
#
  L:=[seq( chi[i]/Pi^(3/2),i=1..8)]:
  Matrix([seq(ListTools:-Rotate(L,j),j=0..7)]);

Matrix(8, 8, {(1, 1) = chi[1]/Pi^(3/2), (1, 2) = chi[2]/Pi^(3/2), (1, 3) = chi[3]/Pi^(3/2), (1, 4) = chi[4]/Pi^(3/2), (1, 5) = chi[5]/Pi^(3/2), (1, 6) = chi[6]/Pi^(3/2), (1, 7) = chi[7]/Pi^(3/2), (1, 8) = chi[8]/Pi^(3/2), (2, 1) = chi[2]/Pi^(3/2), (2, 2) = chi[3]/Pi^(3/2), (2, 3) = chi[4]/Pi^(3/2), (2, 4) = chi[5]/Pi^(3/2), (2, 5) = chi[6]/Pi^(3/2), (2, 6) = chi[7]/Pi^(3/2), (2, 7) = chi[8]/Pi^(3/2), (2, 8) = chi[1]/Pi^(3/2), (3, 1) = chi[3]/Pi^(3/2), (3, 2) = chi[4]/Pi^(3/2), (3, 3) = chi[5]/Pi^(3/2), (3, 4) = chi[6]/Pi^(3/2), (3, 5) = chi[7]/Pi^(3/2), (3, 6) = chi[8]/Pi^(3/2), (3, 7) = chi[1]/Pi^(3/2), (3, 8) = chi[2]/Pi^(3/2), (4, 1) = chi[4]/Pi^(3/2), (4, 2) = chi[5]/Pi^(3/2), (4, 3) = chi[6]/Pi^(3/2), (4, 4) = chi[7]/Pi^(3/2), (4, 5) = chi[8]/Pi^(3/2), (4, 6) = chi[1]/Pi^(3/2), (4, 7) = chi[2]/Pi^(3/2), (4, 8) = chi[3]/Pi^(3/2), (5, 1) = chi[5]/Pi^(3/2), (5, 2) = chi[6]/Pi^(3/2), (5, 3) = chi[7]/Pi^(3/2), (5, 4) = chi[8]/Pi^(3/2), (5, 5) = chi[1]/Pi^(3/2), (5, 6) = chi[2]/Pi^(3/2), (5, 7) = chi[3]/Pi^(3/2), (5, 8) = chi[4]/Pi^(3/2), (6, 1) = chi[6]/Pi^(3/2), (6, 2) = chi[7]/Pi^(3/2), (6, 3) = chi[8]/Pi^(3/2), (6, 4) = chi[1]/Pi^(3/2), (6, 5) = chi[2]/Pi^(3/2), (6, 6) = chi[3]/Pi^(3/2), (6, 7) = chi[4]/Pi^(3/2), (6, 8) = chi[5]/Pi^(3/2), (7, 1) = chi[7]/Pi^(3/2), (7, 2) = chi[8]/Pi^(3/2), (7, 3) = chi[1]/Pi^(3/2), (7, 4) = chi[2]/Pi^(3/2), (7, 5) = chi[3]/Pi^(3/2), (7, 6) = chi[4]/Pi^(3/2), (7, 7) = chi[5]/Pi^(3/2), (7, 8) = chi[6]/Pi^(3/2), (8, 1) = chi[8]/Pi^(3/2), (8, 2) = chi[1]/Pi^(3/2), (8, 3) = chi[2]/Pi^(3/2), (8, 4) = chi[3]/Pi^(3/2), (8, 5) = chi[4]/Pi^(3/2), (8, 6) = chi[5]/Pi^(3/2), (8, 7) = chi[6]/Pi^(3/2), (8, 8) = chi[7]/Pi^(3/2)})

(4)

 


 

Download oddCalc.mw

to use the spacecurve() command to plot 'spikes' at the required points. It can be done (see the attached) - but it seems like an odd thing to do.

For future reference you should upload worksheets using the big green up-arrow in the Mapleprimes toolbar. Many respondents here will not bother to retype code from a picture of your worksheet - it is time-consuming and error-prone

  restart:
  with(plots):

#
# Specify x and y ranges
#
  xrange:=-7..7:
  yrange:=-7..7:
#
# The function
#
  f:=(x,y)->4*y^3+x^2-12*y^2-36*y+x^3+2;
#
# Extreme values of f over specified ranges
#
  extr:=[ maximize(f(x,y), x=xrange, y=yrange),
          minimize(f(x,y), x=xrange, y=yrange)
        ];
#
# Critical points from "first principles"
#
  crits:=[solve([diff(f(x,y),x), diff(f(x,y),y)])];

proc (x, y) options operator, arrow; 4*y^3+x^2-12*y^2-36*y+x^3+2 end proc

 

[926, -2000]

 

[{x = 0, y = -1}, {x = 0, y = 3}, {x = -2/3, y = -1}, {x = -2/3, y = 3}]

(1)

  display
  ( [ #
      # The surface
      #
        plot3d
        ( f(x,y),
          x=xrange,
          y=yrange,
          style=surface
        ),
      #
      # The critical points
      #
        pointplot3d
        ( [ seq
            ( [ rhs~(crits[j])[], f(rhs~(crits[j])[])],
              j=1..numelems(crits)
            )
          ],
          symbol=solidsphere,
          symbolsize=20,
          color=cyan
        ),
      #
      # 'Spikes' through the crital points
      #
        seq
        ( spacecurve
          ( [ rhs~(crits[j])[],t],
              t=extr[1]..extr[2],
              thickness=6,
              color=red
          ),
          j=1..numelems(crits)
        )
    ]
  );

 

 


 

Download crits.mw

Your first calculation returns the squared error, whereas the second returns the error - so the square root of 19/10 is .......?

There are many ways to replicate the error boxes from "first principles", one of them is shown in the attached

  restart;
  pts:= [ [1, 1], [2, 4], [3, 4], [4, 5], [5, 7]]:

  f:=unapply( CurveFitting:-LeastSquares
                            ( pts,
                              x,
                              curve=m*x+b
                            ),
              x
            );
#
# Mean square error
#
  add
  ( ( pts[j][2]-f(pts[j][1]) )^2,
    j =1..numelems(pts)
  );
#
# Mean error
#
  evalf( sqrt(%) );

proc (x) options operator, arrow; 3/10+(13/10)*x end proc

 

19/10

 

1.378404875

(1)

#
# Error plot from first principles
#
  plots:-display
         ( [ plot
             ( [ seq
                 ( [ pts[j][1], f(pts[j][1])],
                   j=1..numelems(pts)
                 )
               ],
               style=pointline,
               symbol=solidcircle,
               symbolsize=16,
               color=blue
             ),
             seq
             (  plottools:-rectangle
                           ( [ pts[j][1], pts[j][2] ],
                             [ pts[j][1]+f(pts[j][1])-pts[j][2], f(pts[j][1])],
                             color=magenta
                           ),
               j=1..numelems(pts)
             )
           ],
           scaling=constrained
        );

 

infolevel[Student[LinearAlgebra]] := 1:
Student[LinearAlgebra]:-LeastSquaresPlot
                        ( pts,
                          x,
                          curve=m*x+b,
                          boxoptions=[color=magenta]
                        );

Fitting curve: .3000+1.300*x
Least squares error: 1.378
Maximum error: 1.100
 

 

 

 


 

Download LS.mw

something like the attached?

  restart;
  with(VectorCalculus):
  v1:=<1+I, 1, I>;
  v2:=<4-1, 0, 2-2*I>;
  DotProduct(v1,v2);

Vector(3, {(1) = 1+I, (2) = 1, (3) = I})

 

Vector(3, {(1) = 3, (2) = 0, (3) = 2-2*I})

 

5+5*I

(1)

 

Download dp2.mw

is shown in the attached

  restart;
  randomize():
  L:=[-1,1];
  r:=rand(1..2):
  numpts:=10000:

[-1, 1]

(1)

  A:=Array(1..2, 0..numpts):
  A[1,0]:=[0,0]:
  A[2,0]:=[0,0]:
  for j from 1 by 1 to numpts do
      A[1,j]:=[A[1, j-1][1]+L[r()], A[1, j-1][2]+L[r()]];
      A[2,j]:=[A[2, j-1][1]+L[r()], A[2, j-1][2]+L[r()]];
  od:
  plot( [ convert(A[1,..], list),
          convert(A[2,..], list)
        ],
        style=line,
        color=[red, blue],
        scaling=constrained
     );

 

 

 


 

Download rWalk.mw

of which three are shown in the attached.

(NB the gridlines don't display in the actual worksheet - they just "appear" when the graphics are rendered on this site!)

  restart:
  with(plots):
  with(plottools):
#
# Generate the plot text to be included in
# all subsequent plots
#
  ptxt:= textplot
         ( [ 3, 3,
             typeset(x=y^2),
             font=[times, bold, 20]
           ]
         ):

#
# Plot y=+sqrt(x) and y=-sqrt(x) then
# combine them
#
  display
  ( [ plot( [sqrt(x), -sqrt(x)],
            x=-5..5,
            color=[blue, blue]
          ),
      ptxt
    ],
    scaling=constrained,
    view=[-5..5, -5..5],
    labels=[x,y]
  );

 

#
# Plot y=x^2 and rotate it
#
  display
  ( [ rotate
      ( plot
        ( x^2,
          x=-2..2,
          color=blue
        ),
        -Pi/2
      ),
      ptxt
    ],
    scaling=constrained,
    view=[-5..5, -5..5],
    labels=[x,y]
  );

 

#
# Use x=y^2 as an implicit plot
#
  display
  ( [ implicitplot
      ( x=y^2,
        x=-5..5,
        y=-5..5,
        color=blue
      ),
      ptxt
    ],
    scaling=constrained,
    view=[-5..5, -5..5],
    labels=[x,y]
  );

 

 

Download para.mw

 

you can use the ApproximateInt() command from the Student[Calculus1] package,  with appropriate options.

See the attached

  restart:
  r:= x -> x*(10-x)/25:
  v:= x -> x*(10-x)/100:
  f:= x -> r(x)*v(x):
#
# Exact solution
#
  int(f(x), x=0..10);

4/3

(1)

#  with(Student[Calculus1]):
#
# 5-point trapezoidal solution ie (0, 2.5, 5, 7.5, 10]
#
  Student[Calculus1]:-ApproximateInt( f(x),
                                      x=0..10,
                                      method=trapezoid,
                                      partition=4
                                    );
  evalf(%);
#
# 5-point midpoint solution
#
  Student[Calculus1]:-ApproximateInt( f(x),
                                      x=0..10,
                                      method=midpoint,
                                      partition=4
                                    );
  evalf(%);
#
# 9-point midpoint solution
#
  Student[Calculus1]:-ApproximateInt( f(x),
                                      x=0..10,
                                      method=midpoint,
                                      partition=8
                                    );
  evalf(%);

85/64

 

1.328125000

 

685/512

 

1.337890625

 

10925/8192

 

1.333618164

(2)

 

 


Download approxInt2.mw

It is generally a bad idea to use variable names "out-of-scope" - whilst it can be done, in some simple cases, (see the first execution group in the attached), I really would not recommend doing this!

A better(?) approach to your problem is shown in the second execution group of the attached, where one has both a 'local' and a 'global' variable named 'x'

  restart;
  foo1:= proc()
             local x;
             return exp(2*sqrt(1/x^2)*x*ln(x)) + exp(sqrt(1/x^2)*x*ln(x)) ;
        end proc:

  sol1:=foo1();
#
# Check whether 'x' in sol1 is 'global' - it isn't
#
  type( indets(sol1, name)[], `global`);
#
# But one can still place assumptions on it!!
#
  simpSol1:=simplify(sol1) assuming indets(sol1, name)[]>0;
#
# Note that 'x' in simpSol is still not 'global'.
# This is likely to cause complicatons in any subsequent
# calculations
#
  type( indets(simpSol1, name)[], `global`);
#
# This is likely to cause complicatons in any subsequent
# calculations - consider for example simple evaluation
#
  eval(simpSol1, x=3);
  eval(simpSol1, indets(simpSol1, name)[]=3);

exp(2*(1/x^2)^(1/2)*x*ln(x))+exp((1/x^2)^(1/2)*x*ln(x))

 

false

 

x^2+x

 

false

 

x^2+x

 

12

(1)

#
# A much more "hygienic" approach
#
  foo2:= proc(a)
              local x:=a;
              return exp(2*sqrt(1/x^2)*x*ln(x)) + exp(sqrt(1/x^2)*x*ln(x)) ;
         end proc:

  sol2:=foo2(x);
#
# Check whether 'x' in sol2 is 'global' - it is!
#
  type( indets(sol2, name)[], `global`);
#
# So simplification is simple
#
  simpSol2:=simplify(sol2) assuming x>0;
#
# As is evaluation
#
  eval(simpSol2, x=3);

exp(2*(1/x^2)^(1/2)*x*ln(x))+exp((1/x^2)^(1/2)*x*ln(x))

 

true

 

x^2+x

 

12

(2)

 

Download locGlo.mw

 

with the attached?

evalf(Int(x^x, x=0..1));

.7834305107

(1)

 

Download doInt.mw

If you want to obtain the 'absolute' position of the pattern in the string, then just omit the range argument from SearchText(): it is optional!

Both of the results in the attached seem eminently sensible to me!

SearchText("ijklm", "abcdefghijklmnopqrstuvWxy", 5..-5);
SearchText("ijklm", "abcdefghijklmnopqrstuvWxy");

5

 

9

(1)

 

Download st.mw

relevant to your second bullet point - isn't this exactly the type of problem for which dataframes were intended?

Organising the data as a 'dataframe', also makes most of the 'sort' requirements rather easier.

See the 'toy' example in the attached and read the help at

?A guide to Dataframes

#
# Set up simple dataframe. (A column of numerical
# values has been added to OP's original, just for
# illustrative purposes
#
   df:= DataFrame
        ( < "Timber",   "Spruce", 17.5;
            "Steel",    "$355",    1;
            "Concrete", "C35",     3.0
          >,
          columns = [material, type, property ],
          rows = ["Material 1", "Material 2", "Material 3"]
        );
 

DataFrame(Matrix(3, 3, {(1, 1) = "Timber", (1, 2) = "Spruce", (1, 3) = 17.5, (2, 1) = "Steel", (2, 2) = "$355", (2, 3) = 1, (3, 1) = "Concrete", (3, 2) = "C35", (3, 3) = 3.0}), rows = ["Material 1", "Material 2", "Material 3"], columns = [material, type, property])

(1)

#
# Sort the dataframe (alphabetically) by the contents
# lf the 'material' column
#
  sort(df, material);

DataFrame(Matrix(3, 3, {(1, 1) = "Concrete", (1, 2) = "C35", (1, 3) = 3.0, (2, 1) = "Steel", (2, 2) = "$355", (2, 3) = 1, (3, 1) = "Timber", (3, 2) = "Spruce", (3, 3) = 17.5}), rows = ["Material 3", "Material 2", "Material 1"], columns = [material, type, property])

(2)

#
# Reverse sort the dataframe by the length of the entry
# in the 'type' column
#
  f:=(x,y)->`if`(length(x)>=length(y), true, false):
  sort( df, type, f);

DataFrame(Matrix(3, 3, {(1, 1) = "Timber", (1, 2) = "Spruce", (1, 3) = 17.5, (2, 1) = "Steel", (2, 2) = "$355", (2, 3) = 1, (3, 1) = "Concrete", (3, 2) = "C35", (3, 3) = 3.0}), rows = ["Material 1", "Material 2", "Material 3"], columns = [material, type, property])

(3)

#
# Sort the dataframe by numerical values in the 'property'
# column
#
  sort(df, property);

DataFrame(Matrix(3, 3, {(1, 1) = "Steel", (1, 2) = "$355", (1, 3) = 1, (2, 1) = "Concrete", (2, 2) = "C35", (2, 3) = 3.0, (3, 1) = "Timber", (3, 2) = "Spruce", (3, 3) = 17.5}), rows = ["Material 2", "Material 3", "Material 1"], columns = [material, type, property])

(4)

#
# Reverse sort the dataframe by numerical values in the
# 'property' column
#
  sort(df, property, `>`);

DataFrame(Matrix(3, 3, {(1, 1) = "Timber", (1, 2) = "Spruce", (1, 3) = 17.5, (2, 1) = "Concrete", (2, 2) = "C35", (2, 3) = 3.0, (3, 1) = "Steel", (3, 2) = "$355", (3, 3) = 1}), rows = ["Material 1", "Material 3", "Material 2"], columns = [material, type, property])

(5)

 

``

Download df2.mw

First 63 64 65 66 67 68 69 Last Page 65 of 207