Carl Love

Carl Love

28070 Reputation

25 Badges

13 years, 26 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

The first command to try would be fsolve. If you can't make it work, then you should post your equations.

Here is a translation of the Mathematica code

restart:
f:= z-> 1 + 2^(z+1) + 3^z:
L:= 20:
Digits:= 25: #eqv to Mma 'N[..., 25]'
zeros:= table():
for k to 300 do   #eqv to Mma 'Table[..., {k, 300}]'
   lprint('k'=k); #eqv to Mma 'Monitor'
   zeros[k]:= RootFinding:-Analytic(f(z), z, re= k*L..(k+1)*L, im= -10..10);
end do:
zeros:= [entries(zeros, 'nolist')]: #eqv to Mma 'Flatten'
sort(zeros, 'key'= Re);

However, the given function apparently doesn't have any zeros in the given range.

Mathematica's N[..., d] is generally equivalent to Maple's evalf(..., d). However, since Analytic already works in floating point, no evalf is needed in this case.

Such polynomial inequalities should (IMO) be solved with the parametric option:

p:= x^3 + a*x + 2:
solve({p > 0}, {x}, 'parametric');

plots:-display(
   [seq(
      plot(p, x= -3..3, y= -10..10, color= COLOR(HUE, (a+5)/10*.85)),
      a= -5..5
   )],
   thickness= 2
);

It doesn't make sense to me to solve for both a and x. Solving for a alone is trivial. The only interesting case is solving for x.

The quartic:

p:= x^4 + a*x + 1:
solve({p > 0}, {x}, 'parametric');

[Same plot command]:

Perhaps this parametric option should be the default when solve gets a polynomial inequality with a parameter.

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.

 

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