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

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);

Change e^4 to exp(4). Then enter what you have above, ending each statement with a semicolon (if you're using 1D input). Then do

evalf(%);


The evalf is what converts it to a decimal form.

Does something make you think that there are nontrivial solutions? There are none.

There is no numeric option to solve. The equivalent is achieved with fsolve:

fsolve({E||(1..3)}, {c,d,e});

I agree with Axel that you should get rid of simplify(..., size). And don't change it plain simplify either.

Make the determinant computation thus

det_2:= abs(1/LinearAlgebra:-Determinant(J_2, method = minor));

If you make those changes, the whole computation will finish in five minutes or so and use about 1/2 G.

I disagree with Axel's skepticism about the overall feasibility of your computation. I have seen many examples where codegen:-optimize with the tryhard option reduced an expression from thousands of pages to a hundred or so lines of code. And, it does it in a few minutes.

The outer lattice, which is the trees connected by the black lines in the diagram, is 25^2; the inner lattice, the ones connected by the blue-grey lines, is 24^2.

We can use evalindets to set the _NN1~ variables that isolve returns to 0. It can even be a one-liner:

evalindets([seq(rhs(isolve({K*(K-1) > 6*C-2, K>0})[]), C= 2..10)], name, 0);

For the benefit of other readers: the goal here is to find the roots of

tan(sqrt(z)) = sqrt(z)

And I will assume that you're only interested in real roots.

For some reason that I don't understand, the AllSolutions option to solve does not provide any useful formula for the roots. Likewise with applying allvalues to the RootOf formula returned by solve.

The real roots can be found with RootFinding:-NextZero, but there are some subleties in its use. The main sublety here being that you have to give it a range over which to search for roots. First, note that there are no negative real roots, that the first root is 0, and that there is a countably infinite sequence of roots.

Root:= table():  Root[0]:= 0:
for k to 9 do
     Root[k]:= RootFinding:-NextZero(
          z-> tan(sqrt(z))-sqrt(z),
          Root[k-1],
          maxdistance= (Root[k-1]+5)^2
     )
od:
Root:= convert(Root, list);

There are several issues.

  1. Remove the inner brackets. If brackets were needed for mathematical grouping (they're not in this case), they would have to be round parentheses. The outer brackets are fine---they indicate that you're building a list.
  2. You need to give the command evalf(%). This is the command that reduces things, as much as possible, to decimal values.
  3. I can't tell how you entered Pi. If you typed pi, you need to change it to Pi.

If you check these things and it still doesn't work, please upload your worksheet so that I can see what you actually typed.

 

 

Here is a procedure to generate the Matrix A such that A.variables = polynomials. I had to take off the (t)s to do this. That is, I changed a[1](t) to a[1], etc. They can be added back easily at any later time. If you prefer, I can change the procedure so that it takes them off and puts them back.




restart:

eq1:= a[1]*a[2]^2+a[2]*a[3]*a[1]+a[3]^3;

a[1]*a[2]^2+a[1]*a[2]*a[3]+a[3]^3

eq2:= a[1]^3*a[2]^2+a[2]*a[3]+a[2]^3;

a[1]^3*a[2]^2+a[2]^3+a[2]*a[3]

eq3:= a[1]*a[3]^2+a[3]^2*a[1]^3+a[2];

a[1]^3*a[3]^2+a[1]*a[3]^2+a[2]

(**)

MVfactor:= (eqns::{list,Vector}(polynom), vars::{list,Vector}(name))->
# Returns a Matrix A such that A.vars = eqns
     Matrix([seq([seq(quo(r,v,v,'r'), v= vars)], r= eqns)])
;                 

proc (eqns::(({Vector, list})(polynom)), vars::(({Vector, list})(name))) options operator, arrow; Matrix([seq([seq(quo(r, v, v, 'r'), v = vars)], r = eqns)]) end proc

(**)

eqns:= < eq||(1..3) >:
vars:= < seq(a[k], k= 1..3) >:
A:= MVfactor(eqns, vars);

A := Matrix(3, 3, {(1, 1) = a[2]^2+a[2]*a[3], (1, 2) = 0, (1, 3) = a[3]^2, (2, 1) = a[2]^2*a[1]^2, (2, 2) = a[2]^2+a[3], (2, 3) = 0, (3, 1) = a[1]^2*a[3]^2+a[3]^2, (3, 2) = 1, (3, 3) = 0})

 

Test (should get zero vector)

(**)

simplify(A.vars - eqns);

Vector(3, {(1) = 0, (2) = 0, (3) = 0})

 


Download problem_4A.mw


Download problem_4A.mws

 

Change g:-`.` to g:-`*`.

Also, highly recommended: Change array to Array and get rid of evalm.

Recommended: Check out ifactors to replace ifactor. The output format is easier to work with in programs (do op manipulations, etc.); ifactor is mainly for interactive display.

No integer whatsoever has the stated property since 2014 is divisible by primes greater than 9, namely 19 and 53.

ifactor(2014);
                         (2) (19) (53)

A more interesting year for this question will be 2016 = 8*7*4*3*3.

The technique for solving this problem is essentially the same as for your previous problem.


(**)

restart:

readdata("C:/Users/Carl/desktop/t.txt"):

T := Vector(%, datatype = float[8]):

readdata("C:/Users/Carl/desktop/i2.txt"):

idata := Vector(%, datatype = float[8]):

(**)

Model:= i[s]*(1-exp(-(t/tau)^d));

i[s]*(1-exp(-(t/tau)^d))

FIT := Statistics:-NonlinearFit(Model, T, idata, [t], output = [residualsumofsquares, parametervalues]);

[0.212347302318356e-8, [d = HFloat(0.3048276105378924), tau = HFloat(1.361653413160606), i[s] = HFloat(1.1766215946973502e-4)]]

(**)

Curve:= plot(eval(Model, FIT[2]), t= min(T)..max(T)):

(**)

Points:= plot(< T | idata >, style= point, color= green):

(**)

plots:-display([Curve, Points]);

(**)

Model:= unapply(eval(Model, FIT[2]), t);

proc (t) options operator, arrow; HFloat(1.1766215946973502e-4)-HFloat(1.1766215946973502e-4)*exp(-HFloat(0.9101915620796802)*t^HFloat(0.3048276105378924)) end proc

(**)

writedata("C:/Users/Carl/desktop/out_i2.txt", convert(map(Model, T), list));

(**)

 

``


Download I-T.mw

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