Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

What do want to do with the expression? It has 44,784 terms (as determined by nops). You can see any individual term, for example the 1000th term, by

op(1000, Eq1);

 

1. What do you mean by "eliminate"? Do you mean to set to 0 or 1? You can find all derivatives taken with respect to in an expression ex by

indets(convert(ex, diff), 'diff'(anything, identical(x)));

You can find all derivatives of any abstract function of the three variables xyz, in that order, taken with respect to x in an expression ex by

indets(convert(ex, diff), 'diff'(anyfunc(identical~([x,y,z])[]), identical(x)));

2. The gradient of a vector-valued function of vector arguments is a matrix called the Jacobian. You can get it with command VectorCalculus:-Jacobian.

Here's a binary infix operator that meets your needs. I wrote it to work for Vectors or lists. In order to work properly with sort, the operator must return true when the vectors are equal.

`&<`:= proc(x::~Vector, y::~Vector)
local n:= op(1,x), i;
     for i to n while x[i] = y[i] do end do;
     i > n or i::even and x[i] > y[i] or i::odd and x[i] < y[i]
end proc;

You can use it like ordinary <:

[1,0,0,1] &< [1,1,0,1];

To use it to sort a list of vectors, pass it to sort with the quotes:

sort(L, `&<`);

I coded this under the assumption that the vectors would be the same length. If you need it to work on vectors of different lengths, let me know.

Your post is very difficult to follow. I think that your main problem is your failure to use a multiplication sign after the C. With that change, it is very easy to get nonlinear fits, as in the following worksheet. It looks like the exponential fit is better.


m3:= Matrix([[0, 0], [1, 1], [2, 3], [3, 5], [4, 7], [5, 8], [6, 9], [7, 10], [8, 10.5], [9, 10], [10, 9.8], [11, 9.8], [12, 10.5], [13, 10.89], [14, 11.2], [15, 10.6], [16, 9.85], [17, 9.45], [18, 9.77], [19, 10.15], [20, 10.7], [21, 10.04], [22, 10], [23, 10.85], [24, 10.7], [25, 10.94], [26, 10.81], [27, 10.33]]):


SphericalModel:= C/2*(3*x/a - x^3/a^3):

FitS:= Statistics:-NonlinearFit(
     SphericalModel, m3, x, output= parametervalues
);

[C = HFloat(12.187034167337886), a = HFloat(18.720074027674276)]

plots:-display(
     plot(m3, style= point, symbol= diamond, symbolsize= 9),
     plot(eval(SphericalModel, FitS), x= 0..27, color= black)
);

ExponentialModel:= C*(1-exp(-x/a)):

FitE:= Statistics:-NonlinearFit(
     ExponentialModel, m3, x, output= parametervalues, initialvalues= [C=1,a=1]
);

[C = HFloat(10.626282498979783), a = HFloat(3.804796639212232)]

plots:-display(
     plot(m3, style= point, symbol= diamond, symbolsize= 9),
     plot(eval(ExponentialModel, FitE), x= 0..27, color= black)
);

 


Download NonlinarFit.mw

You have many problems in the code. Some are errors, and some are just sloppiness. As Georgios already mentioned, Restart should be restart, and gamma cannot be global.

Some other problems:

The proc line should not end with a semicolon.

The local variables should be declared local.

Your algebraic expressions are very bloated with unnecessary parentheses.

The local value sigma is assigned but never used.

Here's my slightly improved code:

restart;
global a:=0.0065, R0:=1.225, T0:=273.16, R:=287.04;
Spd:= proc(H, T1, IAS)
local gamma:= 1.4, T, rho, sigma, EAS, TAS, SpdSnd;
     T:= T1+T0;
     rho:= R0*(1-(a/T*1000)^4.26);
     sigma:= T0/T*(1-(a/T0*H)^5.26); #Warning: not used!
     EAS:= sqrt(rho*IAS^2/R0);
     TAS:= EAS*sqrt(R0/rho);
     SpdSnd:= sqrt(gamma*R*T);
     TAS/SpdSnd;
end proc;

 

Another method: Use a sparse table:

 T := table(sparse, ["green" = "gruen", "red" = "rot", "blue" = "blau"]);

Then unassigned table entries will equal 0.

I've compared the two methods timewise, and I find no significant difference when "hits" are unlikely. (The time difference is within the amount I usually atrribute to random variation.)

restart:
N:= 2^22:
for k to 3 do L||k:= RandomTools:-Generate(list(integer, N)) end do:
ct:= 0:
st:= time():
T:= table(sparse, L1=~L2):
for k in L3 do if T[k] <> 0 then ct:= ct+1 end if end do:
time()-st;
ct;

     25.641
     14

restart:
N:= 2^22:
for k to 3 do L||k:= RandomTools:-Generate(list(integer, N)) end do:
ct:= 0:
st:= time():
T:= table(L1=~L2):
for k in L3 do if assigned(T[k]) then ct:= ct+1 end if end do:
time()-st;
ct;

     25.031
     14

I also did a test where hits were likely, and in that case using assigned was significantly faster. The only difference in the code is that integer becomes integer(range= 1..N). This makes the probability of a hit 1 - exp(-1) ~ 63%.

That should be dsolve({sist, cond[i][]}, ...rather than dsolve({sist, cond[i]}, ...). Notice the extra empty square brackets. They are to convert the list cond[i] into a sequence.

There is already a command that is fairly close to what you want: numtheory:-factorset. You just need to multiply the elements:

rad:= (n::integer)-> `*`(numtheory:-factorset(n)[]);

Answering your followup question, note that the product of a list or set is `*`(L[]), not `*`(L).

You can do the same thing in Maple: Enter your expression with single forward quotes. There are certain small operations (such as arithmetic) called "automatic simplifications" that will always be done. But most operations will be suspended by the quotes. To evaluate the expression after it has been entered this way, use the ditto operator: %


'int(x, x= 0..1)';

%;

The vast majority of Maple commands use global variables (such as enviroment variables, especially Digits) to some extent. Thus they can't run multi-threaded. See ?index,threadsafe for the paltry list of exceptions.

If you are interested in a hardware floating-point answer (aka "double precision"), then the following works in parallel and should give you a processor utilization percentage in the high nineties:

Sin:= proc(x)
option threadsafe, autocompile;
     sin(x)
end proc:

Cos:= proc(x)
option threadsafe, autocompile;
     cos(x)
end proc:

SC:= Threads:-Seq([Sin(i), Cos(i)], i= 1..10^6):

Try this:

Test:= proc(j)
local x;
     plot(x^j, x= -2..2)
end proc:

for j to 3 do
     print(Test(j));
     print(`Press RETURN to continue.`);
     readline(-1);
end do:

The help at ?readline says that the -1 argument avoids the dialog box and reads from the prompt. I get a dialog box anyway.

I assume that you mean that you want the powers of t up to 3, but that the other variables can have higher powers. Use series (after correcting the syntax of your expression):

series(lhs(p1), t, 4);

I believe that evalf is giving up in some cases because it cannot control the error to within the value specified by Digits.

Twelve years ago I wrote a program for the numerical evaluation of infinite series whose summands can be symbolically integrated. Your series is certainly in that category. That program still runs fine in today's Maple. It has a parameter for the maximum absolute error. The attached worksheet includes a derivation of the formula with diagrams, a proof of the formula, the program, and many examples of its use. At the very end, I put your problem. I thought that the worksheet was too long to post inline, so you'll have to download it.

IntTest.mw

For whatever reason, the command requires a symbolic second argument. You can get around this by substituting the numeric second argument into the expanded form, like this:

eval(expand(QDifferenceEquations:-QPochhammer(-1,q,10)), q= 5);

You need to use round parentheses ( ) for all algebraic groupings, not square brackets [ ], in your eqd1 and eqd2.

First 259 260 261 262 263 264 265 Last Page 261 of 395