Carl Love

Carl Love

27291 Reputation

25 Badges

11 years, 361 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

You have Digits set to 5. This is often too few digits for fsolve to work with. I changed Digits to 15 for your first failed fsolve, and I got 0.172565524511021. If the extra digits are irrelevant, just truncate them.

Your second failed fsolve is not the same expression as the first!! Nor is it the same as the plotted expression. If I make it the same expression and change the range to 0.3..0.35, I get 0.309465065970785.

Here is the slightly modified worksheet:

Maple_-_Upload.mw

If the goal is some compact Maple code for it, then do

select(isprime, [$1..300]);

If the goal is efficiency, then use a Sieve of Eratosthenes, like this:

N:= 300:
P:= Vector(N, [0], fill=1):
for k from 4 by 2 to N do  P[k]:= 0  end do:
for p from 3 by 2 to isqrt(N) do
     if P[p]=0 then  next  end if;
     for k from p^2 by p to N do  P[k]:= 0  end do
end do:
convert(ArrayTools:-SearchArray(P), list);


(**)

restart:

Possible values of X are 2,3,4,5.

Common denominator:

(**)

d:= binomial(6,2);

15

X=2 can only be made by drawing two 1s.

(**)

P(X=2):= binomial(3,2)/d;

1/5

X=3 can only be made by drawing a 1 and a 2.

(**)

P(X=3):= binomial(3,1)*binomial(2,1)/d;

2/5

X=4 can be two 2s or a 1 and 3.

(**)

P(X=4):= (binomial(2,2)+binomial(3,1)*binomial(1,1))/d;

4/15

X=5 has to be a 2 and 3.

(**)

P(X=5):= binomial(2,1)*binomial(1,1)/d;

2/15

Check that it's a PDF:

(**)

add(P(X=k), k= 2..5);

1

Mean:

(**)

mu:= add(k*P(X=k), k= 2..5);

10/3

Variance:

(**)

var:= add((k-mu)^2*P(X=k), k= 2..5);

8/9

(**)

 


Download probability.mw

This one can be entered into Maple pretty much as it is written above:

restart:
F:= f@g:  f(-1):= 8:  D(f)(-2):= 4:  D(f)(5):= 3:  g(5):= -2:  D(g)(5):= 6:
D(F)(5);
                               24

Diff(5,x):  % = value(%);

Is that good enough?

Note that the last two substitutions cannot be ranked by complexity because the second-to-last has an extra minus sign. These two need to be applied together. This takes about 20 seconds. Then the first eight substitutions can be applied sequentially. This happens almost immediately, and the result is completely substituted and simplified.

For some reason I can't upload the worksheet for display, but it is attached below. 

Download ans_ss.mw

Here's how to use `if` in a plot command. Note that `if` is in single back quotes (accents graves). Also note that there are no parentheses required for your expression.

expr:=
     21430.800231 - x*359.016725 - x/y*389.223603 +
     x*x/y*6.487414 + 118.7333*0.109468
:

plot3d(
     subs(_E= expr, `if`(x/y > 59, undefined, _E)), x= 53..70, y= 1..1.3,
     grid= [20,20], axes= boxed
);

I can't see your commands, but your output is weird: You should never have cos in an algebraic expression not followed by parentheses. And what does fp mean? You may need to do a restart. Here's what I get:

 

(**)

restart:

(**)

H:= (d-1)*cos(f(y))^2+y^2*diff(f(y),y)^2:

(**)

diff(H, y);

-2*(d-1)*cos(f(y))*sin(f(y))*(diff(f(y), y))+2*y*(diff(f(y), y))^2+2*y^2*(diff(f(y), y))*(diff(diff(f(y), y), y))

(**)

combine(%);

-(diff(f(y), y))*d*sin(2*f(y))+(diff(f(y), y))*sin(2*f(y))+2*y*(diff(f(y), y))^2+2*y^2*(diff(f(y), y))*(diff(diff(f(y), y), y))

(**)

simplify(%, size);

(diff(f(y), y))*(2*(diff(diff(f(y), y), y))*y^2+2*(diff(f(y), y))*y-sin(2*f(y))*d+sin(2*f(y)))

(**)

 

It could still be simplified a bit, IMO, but it is very difficult to get Maple to do more.

Download diff.mw

It is normal for some of the parameters to hypergeom to be the empty list [].

Your answer in this case can be converted to another form:

convert(%,  StandardFunctions);

will convert it to a representation in terms of BesselI and GAMMA functions.

 

Also, restart must be spelled in all lowercase letters; Restart does nothing.

Addressing your other question, your code contains these lines:

 eval(J, [seq](y[k]= Y[k], k= 1/2..3, 1/2)),       
 <eval(K, [seq](y[k]= Y[k], k= 1/2..3, 1/2))>

But is a Vector, so it can only be indexed by positive integers, 1..6 in this case. So you can change that to

 eval(J, [seq](y[k]= Y[2*k], k= 1/2..3, 1/2)),
 <eval(K, [seq](y[k]= Y[2*k], k= 1/2..3, 1/2))>

Your next problem is that K has not been defined. I think that you meant M.

Addressing your question about formatting the output of fsolve, it can be done like this:

vars:= x,y:
e||(1..2):= 'randpoly([vars])' $ 2:
eval(<vars>, fsolve({e||(1..2)}, {vars}));
          

dsolve((D@@2)(y)(x) + 4*y(x) = sin(2*x));

What you are trying to do is possible, but it would probably be easier to use the view option, which essentially cuts away parts of the plot after the fact. For example,

plot3d(x^2+y^2, x= -1..1, y= -1..1, view= [0..1, 0..1, 0..1]);

However, if the region that you want to show is not rectilinear, then you may need to do something with if. It would help if I could see your code.

L:= [seq([n, parse(cat(ListTools:-Reverse(convert(n, base, 7))[]))/n], n= 1..3000)]:
map2(op, 1, select(x-> x[2]=2, L));

I have no proof that there are none larger, but the following plot is rather convincing.

plot(L);

This is a kludgy workaround, but it may be the best possible. You have to use the prefix form of if for this to work.

 

 

(**)

g:= i-> `if`(i <= 1 and i >= 1, a, 0):

(**)

h := sum(g(i), i = 1 .. f);

sum(`if`(i <= 1 and 1 <= i, a, 0), i = 1 .. f)

(**)

eval(subs(f= 3, h));

a

(**)

 

You also have to use eval(subs(...)) to evaluate it; two-argument eval won't work.

Download if_sum.mw

First 344 345 346 347 348 349 350 Last Page 346 of 390