tomleslie

13876 Reputation

20 Badges

15 years, 169 days

MaplePrimes Activity


These are answers submitted by tomleslie

If you just want to know the answer, then you can use the inbuilt function NumberTheory:-ModularLog(). In the example you provide

a:=3:
b:=64:
n:=137:
NumberTheory:-ModularLog(b,a,n);

returns 60, as expected. (note the somewhat unintuitive ordering of arguments for this function - use ?ModularLog to check the help page for clarification).

If you actually do want to write the code yourself (eg as a learning exercise) then asking someone her to write it for you would seem to defeat the object?

I'm certain that you have some pretty significant syntax errors, but I don't really think these should have cause a kernel problem.

I am guessing that you wish to successively compute the indexable quantities X[i], Y[i]. Note that (in Maple), square brackets '[]' are used for accessing indexable quantities. Round brackets '()' are useed for simple term grouping, or to supply arguments to functions.

With this guess in mind, th following code seems to do what you wish, with no problems

m := 2;
X[0] := 14;
Y[0] := 18;
a := 1;
b := 1;
c := .1;
d := 1;
alpha := 1;
for k from 0 to m do
    X[k+1] := GAMMA(k*alpha+1)*(a*X[k]-b*(add(X[s]*Y[k-s], s = 0 .. k)))/GAMMA(k*alpha+1+1);
    Y[k+1] := GAMMA(k*alpha+1)*(-c*Y[k]+d*(add(X[s]*Y[k-s], s = 0 .. k)))/GAMMA(k*alpha+1+1):
end do;

 

If you are evaluatiing the integral of f() over the range 0..1, why are you using function values such as f(2), f(3), and f(4) in your expressions?

You should have something like

f := proc (x) options operator, arrow; cos(6*exp(-x)) end proc;
S := evalf(int(f(x), x = 0 .. 1));
S1 := evalf((1/6)*(1+0)*(f(0)+4*f(1/2)+f(1)));
S2 := evalf((1/12)*(1+0)*(f(0)+4*f(1/4)+2*f(2/4)+4*f(3/4)+f(1)));

I'm probably going to make myself really unpopular here - but why bother using Maple at all????

If the data already exist in EXCEL, then use EXCEL to provide the plot and compute the numeric integral, because

  1. It is trivial to generate the required plot in Excel
  2. It is trivial to perform the required numerical integration in Excel. Assume that the 'x-values' are in column 'A' and the y-values are in column B, then construct the i-th entry in column C as (A[i]-A[i-1])*(B[i]+B[i-1])/2, which translates as bin-width multiplied by average bin value. Then just add the entries in column C using EXCEL's SUM() function, and, hey presto, you have just implemented Simpson's rule

Who needs Maple?

When in doubt, cheat! Use two cylinders, one with a +ve height and one with a -ve height, as in

with(plots):  with(plottools):
Sph := sphere([0, 0, 0], 10,   color=gold, transparency=0.4):
Cyls1 := display([seq(cylinder([0,0,0], h, sqrt(100-h^2), color=red, strips=50),
     h=0..10, 0.2)], insequence):
Cyls2 := display([seq(cylinder([0,0,0], h, -sqrt(100-h^2), color=red, strips=50),
     h=0..10, 0.2)], insequence):
display([Sph, Cyls1, Cyls2], style=surface, lightmodel=light1, axes=none);

 

You use 'm' in the initial parameter list, then 'M' in the differential equations. I assumed that these where intended to be the same, so chnaged the parameter list to read M := 2.

dsolve() then failed because the system is singular at the left endpoint: changed to a midpoint solution method

dsolve() then failed becuase it was unable to achieve desired accuracy: changed abserr to 1.0e-01, just to get something to run. This now works. If more accuracy is desired then try incrreasing maxmesh from the default while decreasing abserr

Inserted a simple plot command just to illustrate F(ta), G(eta), H(eta).

See the attached

ode.mw

Not really sure what you are hoping to achieve with last few commands, ie

dsol1x := subs(dsol1, F(eta));

dsol1y := subs(dsol1, G(eta));

dsol1z := subs(dsol1, H(eta));

So I just deleted these (for now)

I find your syntax simultaneously exceptionally verbose and confusing - so I have had to make multiple guesses about what you intend!! The chances that all of my guesses came out correct are pretty small, but you might want to consider the following to see if it comes close to what you want

restart;
N := 5:
for k from 1 by 1 to 5 do
      c__||k := Matrix( 3, 3, (i,j)->`if`(i*j=3 or i*j=6, 0, cat(c,k)||__||(cat(i,j))));
od:
Q := Array( 1..3, 1..3, 1..N, (i, j, k)->c__||k[i, j] ):
Z := Vector[column](N+1, symbol=h):
A := Matrix(3,3, (i,j)->add( Q[i,j,k]*(Z[k+1]-Z[k]), k=1..N));

If it doesn't, then I am pretty sure I can supply what you want, provided you can specify it clearly and accurately

.

Maple does not posses the concept of the 'prefix  +', ie where

sigma:=+1;

will not be interpreted as sigma=sigma+1. Some programming languages have this interpretation, some don't - deal with it.

The simplest way ito achieve what is implied by your original code, is probably

restart;
A:= Matrix(3,3,symbol=Q);
B:= Matrix(3,3, symbol=sigma);
Sigma__11:= add
                     ( add
                       ( A[1,i]*A[1,j]*B[i,j],
                          j=1..3
                       ),
                       i=1..3
                    );

 

In the document where you generate the plot, use

p1:=plot(x^2, x=-10..10);
save p1, "plottest.m";

You may (or may not) want to add a full path name to the "plottest.m"  string.

In the document where you wish the graph top appear, use

read "plottest.m";

Again you may want to consider using a full path in the "plottest.m"  string.

The plot will now be in your new worksheet, assigned to the name 'p1' so just execute p1 and the plot should appear. Be careful, because if there is an entity called 'p1' in the new worksheet it will be overwritten

 

 

There are two places in your worksheet where you solve a system of ODEs. In both cases the systems are of the form

Xdot=A.X

where Xdot is the vector of differentials, X is a vector of desired functions, and A is a matrix of (constant) coefficients.

So the only relevant eigenvalues/eigenvectors are those of the matrix A ( see for example https://en.wikipedia.org/wiki/Matrix_differential_equation)

I have added a procedure to your worksheet which accepts an ODE system, and returns the eigenvalues/eigenvectors of the coefficient matrix. I have also inserted the relevant commands to run this procedure at the appropriate points in your worksheet

Please be aware that I am not doing any clever argument checking on the supplied odesystem - whihc might be necessary if you plan on using this for other odesystems

AnSol.mw

so make yourself comfortable, get a drink and be prepared to read/understand a lot of stuff, cos this ain't a simple one!!

  1. 'Mac Dude' stated that *Well, you use x already in your sum; and NLPSolve minimizes a function by varying its independent variables (indets in Maple lingo) so no, you don't need or want x explicitly in NLPSolve". It is true that the variable 'x' is used in your sum()/add() function but only as an index. The result of the sum()/add() function does not contain the variable 'x' and so ' fungsikerugian ' does not explicitly depend on 'x'
  2. In my earlier posts, I stated that you could not use a variable 'x' in your constraints, if that variable did not exist in the objective function (ie ' fungsikerugian '). I was wrong. Although the variable 'x' does not exist in the objective function (see [1] above) it can be used as a variable in the optimization process, provided it is explicitly declared, using the variables=[] option. in the relevant Optimization command. Notice that the declaration here refers to the variable 'x' used in your constraint definition: this has absolutely no relation to the summation index 'x' used in the definition of the objective function  ' fungsikerugian '
  3. Even when I implement (2) above, the Optimization:-NLPSolve() command still fails. I played around with various options, but I generally got error messages such as "undefined value encountered" or "complex value encountered", and it bailed out without producing an answer. So I gave up with these commands/
  4. Next I tried the 'DirectSearch' package. This is not part of standard Maple: it is an add-on package of routines for solving Optimization problems which is available from the Maple Application Centre. Almost certainly you do not have this installed. Sometimes this "works" when the standard Maple routines do not - and sometimes it doesn't. But in my experience it is always worth a try. With a litlle fiddling of options, I actually persuaded this package to provide an answer, which was

soln := [91.4939827859610,
             Vector[column](10, [0.273794828189041e-1, 0.924038056839675e-2,
                                             .999220256006146, .122423412374451,
                                             .586015599662414, .291560985774146,
                                              7.26082370806783, 2.82737386783950,
                                              0.9325459609e-13, 1.08078557224151
                                           ]
                                     ),
             40281
           ]
The first entry in 'soln' (ie 91.4939827859610) is the minimum for your objective function ' fungsikerugian '. The second entry is a vector whose entries correspond to the values of the problem parameters ie [m1, m2, m3, psi1, psi2, psi3, sigma1, sigma2, sigma3, x]. The third entry (40281) is essentially the number of 'iterations' which were required to generate the solution.

The attached worksheet shows the calculation.

I have deliberately saved/uploaded it with output, because if you try to execute, it will almost certainly fail because (I'm guessing that) you do not have the DirectSearch package loaded - so probably safest to treat treat it as read-only. There is a (reasonably) pretty print of relevant output at the end of the worksheet

NLPprob2.mw

 

The following works for me,

ode:=y(x)*diff(y(x),x,x)+diff(y(x),x)^2=0;
bcs:=y(0)=4, D(y)(0)=7;
dsolve([ode, bcs]);

so I cannot imagine what you were doing???

For your example labelled " #my testing for one to one " in your original post, the values of

add(diff1[m],m=1..nops(diff1)),
add(diff2[m],m=1..nops(diff2))

settle very quiclky into the cycles

 1   1 1 1  0  1  1 1 1  0  1   1 1 1 0  1  1 1 1 0 ......

 -1 0 0 0 -3 -1 0 0 0 -3 -1 0 0 0 -3 -1 0 0 0 ......

so the 'if' test

if   add(diff1[m],m=1..nops(diff1)) = 0
     and
     add(diff2[m],m=1..nops(diff2)) = 0

is never true - the two sums are never zero simultaneously, so checksum2[ii] never changes and the 'while' loop will run for ever:-(

and everything can be done using commands from the 'geometry' package. (Or one could use solve() on the equations).

Try the following

   restart;
   with(geometry):
#
# Define first circle and return details
#
   point(P1, 3300, 2200);
   circle(C1, [P1, 110], [x,y]);
   detail(C1);
#
# Define second circle and return details
#
   point(P2, 3410,2090);
   circle(C2, [P2,80], [x,y]);
   detail(C2);
#
# Plot circles just for visualisation
#
   draw([C1,C2], color=[red, blue]);
#
# Compute intersection and return
# intersection details
#
   intersection( S, C1, C2, [I1,I2]);
   detail(S);
#
# Return details of the intersection points
#
   detail(I1);
   detail(I2);
#
# Alternative method for getting intersection
# Use solve() on the equations for the circles
#
   solve([Equation(C1), Equation(C2)], explicit);

Assuming positive roots exist, then just adding the additional inequality x>0  to the system to be solved will generally work

p:= randpoly(x);
solve({p, x>0});

First 173 174 175 176 177 178 179 Last Page 175 of 207