Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 357 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

seq(seq(N[10*i+j], j= 1..3), i= 1..3);

You need to change

end module()

to

end module;

 

Here's how to get numeric dsolve to return the integral of a function of the dependent variable(s).

restart:

eqs:=
   a*diff(x(t),t$2) + (b+sin(x(t)))*diff(x(t),t) + 2/x(t) = 0,
   diff(J(t),t) = x(t)^2  #So J is the integral of x(t)^2.
:   

cis:= x(0) = 0.25, D(x)(0) = 0, J(0) = 0:

(amin, amax):= (0.1, 0.2):

(bmin, bmax):= (15, 24):

a:= abs(amin+(amax-amin)*h):
b:= abs(bmin+(bmax-bmin)*h):
simpfloat:= rand(-1.0..1.0):

Q1:= table():
to 10 do
   h:= simpfloat():
   try
      solut:= dsolve([eqs, cis], numeric, maxfun= 0);
      #Compute Int(x(t)^2, t= 5..6).
      eng:= eval(J(t), solut(6)) - eval(J(t), solut(5))
   catch:
      eng:= FAIL
   end try;
   Q1[a, b, h, eng]:= NULL
end do:
Q1:= [indices(Q1)];      

[[0.561149063e-1, 11.05034157, -.438850937, FAIL], [0.676432597e-1, 12.08789337, -.323567403, FAIL], [0.257136914e-1, 8.314232226, -.742863086, FAIL], [.1431521350, 18.88369215, .431521350, FAIL], [0.648272036e-1, 11.83444832, -.351727964, FAIL], [.1454595796, 19.09136216, .454595796, FAIL], [.1581067165, 20.22960448, .581067165, FAIL], [.1050666015, 15.45599414, 0.50666015e-1, FAIL], [0.224564219e-1, 8.021077971, -.775435781, FAIL], [.1418130698, 18.76317628, .418130698, FAIL]]

(1)
 

 

Download IntByDsolve.mw

In this case the result will always be FAIL by Preben's reasoning. But for other ODEs, you'll generally get numeric values where those FAILs are.

Yes, you can do that with a try statement, like this:

for j from 1 to 10 do
     try
          Sol_set[j]:= solve(f(x,a)=0, x)
     catch:
          Sol_set[j]:= FAIL
     end try
end do;
       

You may replace FAIL with 0 if you really want to.

There's a somewhat-builtin facility for detecting submatrices that are all zeros: ArrayTools:-IsZero.

RemoveZeroRowsAndColumns:= (A::Matrix)->
   A[remove(i-> ArrayTools:-IsZero(A[i,..]), [$1..op([1,1], A)]),
     remove(j-> ArrayTools:-IsZero(A[..,j]), [$1..op([1,2], A)])
    ]
:

I haven't done a time test, but I suspect that this'll be significantly faster than the other Answers on your 1000x1000 matrix.

Suppose that an Array A is declared and initialized with a statement such as

A:= Array(1..9, 1..9);

Now A has two dimensions, usually called rows and columns. In the language of your error message, the number of dimensions is called the rank. (This has nothing to do with the concept of rank of a matrix or linear transformation from linear algebra.) The elements of A can be accessed as A[i,j] where i and j are integers in the appropriate ranges, in this example 1 to 9. The i and j are called indices. If you were to attempt an access of A as A[5,3,7], then there'd be three indices, and the number of indices would exceed the rank, like the error message says. You have something akin to this in your code.

Generally you should post your code. If the code is more than, say, 100 lines, and you are able to isolate the erroneous part, just post that. If you can't isolate it, just post the whole thing. Please post code as either plaintext or a Maple worksheet file. Screenshots or cut-and-paste of 2D input is not helpful.

Your first part is incorrect. Since the two distributions being added are identical, your statement is equivalent (as far as Maple is concerned) to

w:= 2*RandomVariable(BetaDistribution(1, m-1));

and thus the two distributions are not independent. (This is due to Maple's automatic simplification.) To get around the automatic simplification and achieve an i.i.d. (independent identically distributed) sum of RVs (Random Variables), you need to do something like

(X,Y):= 'Statistics:-RandomVariable(BetaDistribution(1, m-1))' $ 2; #Note carefully the quotes.
W:= X + Y;

To achieve your second goal, the simplest imaginable thing works:

X2:= W/2;

I can confirm the bug that you're encountering.

You can use unapply instead of makeproc:

unapply(Myfun, [a,b]);

Assuming that you're restricting the analysis to real numbers, ln(dy/dx) = 0 simply implies that dy/dx = 1. Using the ln just introduces unnecessary complexity.

On the other hand, perhaps you are recalling something that you learned about the derivative of the logarithm rather than the logarithm of the derivative? This is a useful concept.

The command op doesn't "get the variable" in an expression. Please read ?op. To get the variable, assuming that there's only one, use

martin:= indets(f, And(name, Not(constant)))[];

plot(Statistics:-PDF(Weibull(6.2, 2), x), x= 0..26);

Using Statistics:-EmpiricalDistribution, a procedure that generates your parameterized random variable can be written in one line:

MyRV:= (i::posint, x::posint)->
   Statistics:-RandomVariable(EmpiricalDistribution(irem~([$i-x..i-1, $i+1..i+x]  -~ 1, 100) +~ 1))
:

 Example:   
X:= MyRV(98,5):
map(trunc, Statistics:-Sample(X,25));

      [93, 2, 97, 93, 95, 2, 96, 3, 96, 96, 97, 94, 1, 3, 100, 2, 99, 95, 100, 1, 94, 2, 100, 1, 97]

Statistics:-Mean(X);

      68

If your goal is simply to draw samples from the distribution rather than to analyze it, then a much more efficient procedure can be used. On the other hand, if your goal is to express the distribution's statistics (such as Mean) in terms of the parameters i and x, it is significantly more complicated, but still I think doable. Either way, let me know.

 

You are trying to create a Matrix with datatype= float[8]. Such a Matrix is not allowed to contain variables which have not been assigned real numeric values. It looks like you may have two distinct "Delta bar" variables, which look confusingly similar. I need to see a worksheet to say for sure.

The convert command is unnecessary. Once all the variables have been assigned numeric values, you can say

M:= Matrix(K, datatype= float[8]);

You did not directly call evalhf, but it is used in the conversion to float[8], so it was called indirectly.

Maple's rules of operator precedence are a bit weird for mod (see ?operators,precedence): It has different precedence on its left and right sides! You no doubt think that a + b mod c is parsed as a + (b mod c), but it's actually parsed as (a + b) mod c. Furthermore, you can't tell whether it's using mods or modp (see ?mod). Finally, mod is a high-level symbolic operator which probably shouldn't be used in numeric code. If you want the integer remainder, then use the command that's designed for that: irem.

sieve[i+j*j]:= 2 + irem(sieve[i+j*j], 2);

No, but there's enough prime infrastructure built-in such that writing such a procedure is trivial. And here it is:

PrimesBetween:= proc(a::posint, b::posint)
local L:= table(), p:= nextprime(a-1);
   while p <= b do
      L[p]:= [][];
      p:= nextprime(p)
   end do;
   {indices(L, 'nolist')}
end proc:
   
PrimesBetween(100, 200);

     {101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199}

By the way, Maple commands do not generally "print" their output; they return it. Whether the output is printed and where it is printed is determined by a variety of means under the user's control.

First 191 192 193 194 195 196 197 Last Page 193 of 395