Carl Love

Carl Love

28020 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

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

The answer can't be determined from the given diagram. The top triangle is not necessarily right. What appears to be a rectangle may actually be a trapezoid.

 

Make lists of x and y values. They do not have to be the same values or the same number of values.

(**)

X,Y:= [-1,0,1], [-1,0,1]:

Solve equation for z.

(**)

Z:= unapply(solve(x - 3*y + z = 5, z), (x,y));

proc (x, y) options operator, arrow; 5-x+3*y end proc

(**)

Matrix([seq(seq([x,y,Z(x,y)], x in X), y in Y)]);

Matrix(9, 3, {(1, 1) = -1, (1, 2) = -1, (1, 3) = 3, (2, 1) = 0, (2, 2) = -1, (2, 3) = 2, (3, 1) = 1, (3, 2) = -1, (3, 3) = 1, (4, 1) = -1, (4, 2) = 0, (4, 3) = 6, (5, 1) = 0, (5, 2) = 0, (5, 3) = 5, (6, 1) = 1, (6, 2) = 0, (6, 3) = 4, (7, 1) = -1, (7, 2) = 1, (7, 3) = 9, (8, 1) = 0, (8, 2) = 1, (8, 3) = 8, (9, 1) = 1, (9, 2) = 1, (9, 3) = 7})

(**)

 

If you can't see the Matrix (which will happen if it is too large), then issue the command

interface(rtablesize= infinity);

before the Matrix command.

Download table.mw

Excellent question!

First: This has nothing to do with your problem, but you should get rid of with(linalg). You are not using that package anyway, and it is deprecated (not intended to be used in new code).

The key to your problem is to never assign values to the Vector b's symbolic variables, h, y[0], and z[0] in this case. Rather, assign values to different variables and use eval to put them into b. Please let me know if you can understand the following example:


(**)

restart:

(**)

macro(LA= LinearAlgebra): #A bit clearer than using 'with'

Generate a random pair of linear equations with symbolic constant terms as an example.

(**)

eq||(1..2):= 'randpoly([x,y,y[0],h], degree= 1, dense)' $ 2;

-7*x+22*y-55*y[0]-94*h+87, -56*x-62*y[0]+97*h-73

(**)

A,b:= LA:-GenerateMatrix([eq||(1..2)], [x,y]);

A, b := Matrix(2, 2, {(1, 1) = -7, (1, 2) = 22, (2, 1) = -56, (2, 2) = 0}), Vector(2, {(1) = -87+55*y[0]+94*h, (2) = 73+62*y[0]-97*h})

Note that I never assign a value to h or y[0]! In particular, the for loop variable has a different name.

(**)

for h1 from .1 by .1 to .2 do
     y1:= rand(0..9)():
     X:= LA:-LinearSolve(A, eval(b, [h= h1, y[0]= y1]))
     # print out X...whatever
od;  
 

y1 := 0

X := Vector(2, {(1) = -1.13035714285714, (2) = -3.88693181818182})

y1 := 7

X := Vector(2, {(1) = -8.70714285714286, (2) = 11.6295454545455})

Note that b has never changed.

(**)

b;

Vector(2, {(1) = -87+55*y[0]+94*h, (2) = 73+62*y[0]-97*h})

(**)

 


Download evalVector.mw


Please let me know if you have any trouble understanding the example or applying it to your situation.

Generating the Cartesian product of lists (all tuples) is discussed extensively in this post from 2007. Note that if (b+1)^n is large, say greater than 10 million, you may be better off using an iterator, i.e., generating the tuples one at a time rather than all at once (see ?combinat,cartprod ). The cut-off point for using an iterator depends on how much memory you can devote to storing the tuples. If you need help with an iterator, let me know. AFAIK, there is no benefit to using an iterator if you have the memory to do it non-iteratively, because iterators take significantly more processor time.

To generate them all at once, the best of the procedures from the thread mentioned above is this absolute gem of compact self-modifying code by Joe Riel:

CartProdSeq:= proc(L::seq(list))
local Seq,i,j;
option `Copyright (C) 2007, Joseph Riel. All rights reserved.`;
     eval([subs(Seq= seq, foldl(Seq, [cat(i, 1..nargs)], seq(cat(i,j)= L[j], j= nargs..1, -1)))])
end proc:

To use it with the parameters that you specified:

CartProdSeq([$0..b] $ n);

First 349 350 351 352 353 354 355 Last Page 351 of 395