tomleslie

13876 Reputation

20 Badges

15 years, 175 days

MaplePrimes Activity


These are replies submitted by tomleslie

The following will generate the matrix which you want, and add the entries

#
# Procedure which generates matrix given number of
# rows and number of columns: NB probably many ways
# to do this
#
   getMat:= proc( rows::posint, cols::posint)::Matrix;
                           local g:= rand(1..2),
                           f:= x -> (-1)^g():
                           uses LinearAlgebra;
                           RandomMatrix(rows, cols, generator=f);
                 end proc:
#
# Generate *example* matrix and add entries
#
   p:= getMat(8,7);
   add(p);

I have no idea about the next part of the question: any (non-edge) entry has 4 nearest neighbours (8, if diagonals are counted as nearest neighbours). You are going to have to specify what value you want to associate with aij,  given values for ai-1 j-1. ai-1,j, ai-1,j+1, ai,j-1, ai,j+1, ai+1,j-1, ai+1,j, ai+1,j+1

Given the boundary condition y(0)=0, then your second ODE, with x=0 and y(x)=0 reduces to 0/0 - ie it is completely undefined. In other words dz(x)/dx is completely undefined at x=0.

Now you can 'force' a definition, just by changing the boundary conditions slightly - however with x=0, the denominator of diff(z(x), x) at x=0, is definitely 0 - and hence its value will either be 0/0 (ie undefined) or value/0 (ie infinite). However the graph produce appears to dz/dx=0. Exactly why do you expect this to be true????

  1. There is no need to use evalf((1/1000000000000)*rand()) , or anything similar. If the datatype option in the Matrix() constructor is set to float[8], then any data you generate ( from 'rand' or wherever) will automatically be converted/coerced (pick your terminology) to 8-byte, floating point numbers. See the code listiing in my original post
  2. You probably don't need the useHardwareFloats command. As it returns 'deduced', this mean that Maple will use hardware floats when appropriate. In your case, since you define a Matrix with hardware floats (ie float8), then Maple will (by default) carry out all numerical operations involving this matrix using hardware floats. It is possible to configure Maple to 'always' use hardware floats - or 'never' use hardware floats. Don't play with these settings unless you really, really know what you are doing - just let Maple 'deduce' it
  3. Precision?? This is a discussion I really don't want to get into!! Maple implements the IEEE754 standard, which means that your 'precision' is 53 bits, or roughly 15.955 digits. This is not the same as setting Digits=15, although the 'practical' difference may be minor. Note however that when adding/multiplying/whatever two such numbers, rounding will occur. The more involved the calculation, the  more potential there is for rounding at each stage. I think it would be a brave (wo)man who 'guaranteed' 15-digit precision in a complicated calculation. This i not a shortcoming of Maple - just a limitation of using 8-bytes (ie 'double precision')  to express floating point numbers
  4. For floating point Matrix manipulation, Maple/Matlab/Mathematica all use the industry-standard BLAS/LAPACK combination. Maple and Mathematica will do a small amount of type-checking before firing up the LAPACK routines, but the impact this has on overall timings is negligible. This generally means that all three of these applications will produce similar timings for similar problems. Anyone who claims that one is 'faster' than the others for this class of problem *probably* doesn't know what they are talking about

When looking for a known number of roots in a known range, the RootFinding:-NextZero() command is quite useful. In your case one would have something like

   f:=exp(x-188.5)-4*x^2+1507.964*x-142122.3+cos(x)^2;
   g:=(-f+x^2-376.991*x+35530.6)/(f+x^2-376.991*x+35530.6);
   plot(g, x = 186 .. 194, y = -25 .. 25,discont=false);
#
# Get nRoots, starting from xmin
#
   nRoots:=3:
   xmin:=186:
   ans:=Array(1..nRoots):
   for k from 1 by 1 to nRoots do
        ans[k]:=RootFinding:-NextZero(unapply(denom(g), x),xmin);
        xmin:=ans[k];
   od:
   ans;

 

 

First of all, your new fitting model, ie

ln(k)-(E)/(8.314*873.15)*x

is the equation of a straight line - ie it is of the form y=m*x+c - schoolboy straight line.

Unfortunately your data points exhibit a bit of a "curve". Fitting a straight line to curved data is never going to produce a *great* answer.

However both Startistics:-Fit and DirectSearch:-DataFit produce essentially the same answers, with no problems No mention of "complex values encounterred".

See the attached for fitting the data you supplied to the model you supplied using both Statstics:Fit and DirectSearch:-DataFit

dataFit2.mw

I ahve modified my previous worksheet a litt so that it now produces plots as well as tabular data

I have "scaled" the plots so that diameter is in cm, and pressure is in MPa - your Excel sheet appear ot be in 'imperial" units ( ie inches and bar). I have not bothered to perform the metric->imperial conversion. See the attached

useMatrix2.mw

You state that you think the result are "a little off"??? If this is true then the only possibility is that (somewhere) I have written a Matrix initilialiser function incorrectly. I have rechecked, and can't see anything, but I could be wrong. I have no realistic way of checking this, since I don't know the answers you expect!!! Can only suggest that you double-check my code ( and also the process whihc gives you the answer you expect!)

You are correct - it is horrible: but all you need to do is to learn how to write matrix initializer functions properly

The attached shows my attempt - beware, the probability that I can write this much code without having a typo somewhere is a bit small, so you should check very carefully that the (i,j)-th entry in each Matrix() has been defined correctly.

I think they are all correct, but I wouldn't want to guarantee it :-(

useMatrix.mw

Since the problem is symmetrical wrt a, b, the following gives the same answers, but slightly quicker

select(isprime, {seq(seq(a^b+b^a, a= b..99), b= 2..99)})[1..10];

Not sure how you can guarantee that either method is generating the 'first' 10 primes - consider the number 3^100+100^3 - which is certainly less than the 10-th number in the obtained list. Luckily(?!) this one isn't prime. But it is trivial to generate numbers less than those in these lists, using start pairs not contained within the lists .... so this is a kind of open-ended problem.

OEIS confirms that the numbers generated are the 10 lowest primes - but I don't see how this can be proved.

I cannot reproduce your problem exactly, because in Maple 2016.1, terms in the expression 'dairihensu1' always appear in the same order. In Maple 18 the order is consistent, but different from that obtained in Maple 2016, and so you code fails in Maple 18, because the op() selector

[2,4,1,3,2

fails!

So I tried to come up with code which would work in both Maple 18 and Maple 2016 producing identical final expressions - and I failed!!

The code

restart;
e7_4:=F__D*(Omega+1)*beta/(beta-1) = F__I*a__D^(-k)*a__0^k+T^((sigma-k-1)/(-1+sigma))*F__D*phi^(k/(-1+sigma))+F__D;

a1:=beta=k/(sigma-1);
subs_free:=proc(a,b,c)
                local b1;
                b1:=isolate(b,c);
                simplify(subs(b1,a), size);
           end proc;
e7_5:= subs_free
       ( simplify
         ( isolate
           ( e7_4, a__D^(-k) ),
           symbolic
         ),
         a1,
         sigma
       );

gets very close. It works in both Maple 18 and Maple 2016, simplifies the exponents etc. The terms in the numerator of the final expression are identical, but they appear in different order: Maple 18 returns

(term_in_a0)*( everything_else)*(term in FD)

and Maple 2016 returns

(term_in_FD)*( everything_else)*(term in a0)

Not sure why you think you would end up with a lot of zeros, Consider your definition ov 'v' which is a 9-element vector, each of whose entries is a 5-element vector: this is 45 entries organise 9*5 - so what is wrong with

v :=  Matrix
        ( op(1, V__dot),
          op(1, A),
          (i, j) ->combine(V__dot[i]/A[j], 'units')
       );

Your original post suggest you need 45 data points - to me a matrix with 45 entries seems like a step forward

whihch gives the same 45 enntries - just organised differetnly

 

I cannot understand what you are trying to achieve.

I think your problems start when you choose to construct a 9-element vector, each of whose entries is a 5-element vector. You can use 'map' (or elementwise operators) to perform elementwise operations on a vector - but when you have a vector of vectors, I'm pretty sure that you are going to need 'nested' map operations to perform any elementwise operations on the 'inner' vectors.

So instead of creating a 9-element vector whose entries are 5-element vectors, wouldn't it have been easier to create a 9*5 (or 5*9) matrix. You can then use a single, non-nested, map() function (or elementwise operators) to perform elementwise operations

You need to specify much more clearly what you mean by

if I can add a multiplier to my equation in a specific range.  So starting from z:=0.2 add a multiplier (z+1)

Which equation do you want to muliply???? If I knew this it would be trivial to do

One interpretation (which I do not believe is correct, becuase it leads to a discontinuity in your graph), would be the following

restart; 
with(plots):
a := -1/2; b := 1/2; c := -2; d := 2; n := 20; 
g := proc(x)
          options operator, arrow;
          value
          ( Int
            ( sigma(t),
              t = 0 .. x
            )
          )
     end proc; 
sigma := proc(z)
              options operator, arrow;
              2*sqrt(2*h^2-4*z^2)*z/h^2;
         end proc; 
h := i/n; 
for i to n do 
an2[i] := plot( `if`
                ( z>0.2,
                  (1+z)*sigma(z),
                  sigma(z)
                ),
                z = -(1/2)*h .. (1/2)*h,
                view = [a .. b, c .. d],
                color = AQUAMARINE
              ); 
an3[i] := plot( 2*g(x),
                x = 0 .. (1/2)*h,
                view = [a .. b, c .. d],
                color = RED
              ) 
end do:
p := plots[display]([seq(an2[i], i = 1 .. n)], insequence = true); 
q := plots[display]([seq(an3[i], i = 1 .. n)], insequence = true);
display(p, q);

Note the 'if' condition in the first plot() statement

Your question is imcomplete - so I do not understand what you want

When I started this I too thought that there must be an "easy way" - and I'm still vaguely surprised that there isn't

As Carl has pointted out these are three 2-D plots, so I do not understand your reference to 3D plotting.
These can be plotted separately, or on one single plot with the following

with(plots):
p1:=plot(2*(exp(-0.15*(u)^1.5))*(u)^0.5,u=0..2);
p2:=plot([0.2*(x-sin(x)),0.5*(1-cos(x)),x=0..10*Pi]);
p3:=polarplot(4+1*cos(5*x),x=0..2*Pi);
display( [p1,p2,p3]);

First 135 136 137 138 139 140 141 Last Page 137 of 207