Carl Love

Carl Love

28025 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

In the following line, you've misspelled indkomst as indomst:

elif 44000 < 0.92*indkomst and indomst <= 44000+fradrag then

Your worksheet begins with the line

restart; ... several with commands ....

But, the restart command should always stand alone in its own execution group. Failure to do so can cause intermittent and irreproducible errors related to the other commands on the same line not being executed.

I cannot test this solution for you because the error is, of course, irreproducible for me.

And, personally, I never rely on the with command to find procedures for me. This is not because I think that there's some bug in with; rather it's because I think that it leads to less-readable code.

Change the line

A:= seq(...)

to

A:= < seq(...) >

This will make a Vector rather than a sequence. The Export command (like almost all commands) cannot except a sequence as an argument.

Here's an example. Here's two 2x3 matrices:

A:= <1, 2, 3; 4, 5, 6>; 
B:= <a, b, c; d, e, f>;

This command will take the 2nd row of each and combine them into a new 2x3 matrix:

C1:= <A[2,..], B[2,..]>;

This command will take the 2nd row of each and adjoin them side-by-side:

C2:= <A[2,..] | B[2,..]>;

For the first of these combinations it's of course required that the number of columns be the same in A and B. For the second, that's not required.

Regarding your first question---selecting the 3rd element from each sublist of a list of lists L1---here are three more ways to do it. I find these more intuitive, although there's hardly any difference in efficiency compared to the other Answers.

L1[..,3];
index~(L1, 3);
op~(3, L1);

Experienced Maple users may be surprised that the first of these--which uses Matrix-style indexing--works even if the sublists have different lengths, that is, if L1 cannot be interpreted as a Matrix.

Regarding your third question---sorting a list of lists L3 based on the 3rd elements---here is a better way, both more intuitive and (slightly) more efficient:

sort(L3, 'key'= (L-> L[3]));

For a very long list, a key sort is more efficient than a sort that uses a comparison function because the key of each entry only needs to be extracted once.

Inside procedure U, you've used the names `U__&eta` and `U__&theta`. But in procedure plug, you've used U__eta and U__theta. These are completely different names to Maple even though they appear the same when prettyprinted.

Have you checked the help page ?index,threadsafe to check whether your code is threadsafe? What you described is common if you try to use procedures that aren't threadsafe with Threads.

Usually it is not necessary to quit Maple entirely, despite what the "lost kernel connection" message on your screen might say. Usually you just need to kill the errant kernel process and close and re-open its assocciated worksheet. If you have multiple worksheets open, doing it this way is much less grief.

By hand (actually, in my head), I isolate the relevant derivative: 

ode:= diff(x(y),y) = a*y^(-6*b-1) - 4*x(y)/y;

Then use dsolve:

dsolve(ode);

    

How about the simple and obvious 

Linear:= (f::polynom, V::{list,set}(name):= indets(f, And(name, Not(constant))->
   evalb(degree(f, V) <= 1)
:

The problem is that much time is wasted on futile symbolic computation of the integrals. Put the option numeric in your integrals. Get rid of evalf. Example:

Digits:= 15:
int(79.977249/(z+7.943)^2/(z^0.1408592322+7.943), z= 1..infinity, numeric);
                       
0.953406537701741

That's returned in 0.016 seconds.

Acer's suggestion of evalf(Int(...)) is essentially equivalent to the above. We were just writing our Answers at the same time.
 

So, without showing any apparent reason for doing so, you use this crazy value 50 billion as one of your upper limits? Reduce that value to a reasonable size and the command will work quickly.

What do you expect to happen if there are a billion roots? that they'd be printed on your screen? Unless you have some unusually massive computer, they wouldn't even fit in your RAM.

C'mon, are you seriously trying to claim that you didn't already know, or at least strongly suspect, that this 50 billion was the source of your error? And if you already suspected that, why didn't you try changing it?

Here are procedures for the primary and inverse functions:

Lehmer:= (S::And(list(nonnegint), satisfies(S-> max(S)=nops({S[]})-1)))-> 
   Rank(Iterator:-Permute([{S[]}[]]), S) - 1
:
LehmerInv:= (s::nonnegint, n::And(posint, satisfies(n-> s < n!)))->
   [seq(Unrank(Iterator:-Permute(n), s+1) -~ 1)]
:

 

Your fsolve is returning unevaluated for some loop iteration. This can mean several things, all of which commonly occur:

  1. There is actually no solution.
  2. fsolve thinks that there is no solution even though there actually is. In other words, some iterative process akin to Newton's method is diverging for every initial value that it tries.
  3. fsolve knows that there is a solution, but it can't refine it to sufficient accuracy. In other words, the iterative process is converging, but there's some oscillation in the last few digits.

So, whenever fsolve is used programmatically, such as in a loop, you should check the form of the returned value (your S) to make sure that it isn't of the form fsolve(...) before that S is used in a further computation. Do something like this:

Failures:= table();
for i ... do
    ...; 
    S:= fsolve(...);
    if eval(S,1)::specfunc(fsolve) then 
       Failures[i]:= eval(S,1)
    else
       w(i):= eval(k, S)
    end if
end do: 
eval(Failures);

 

At the end, Failures will contain all the cases for which fsolve didn't converge. You may decide to analyze these further, or you may decide that the cases that did converge are sufficient for your purpose.

If you need further help with this, please post your complete code.

Here is a procedure to return the dependent variables from a PDE, ODE, or a set or list thereof:

depvars:= (pde::{algebraic, `=`(algebraic), {set,list}(algebraic, `=`(algebraic))})-> 
   indets(
      indets(convert(pde, diff), specfunc(diff)), 
      And(typefunc(name, name), Not(typefunc({mathfunc, identical(diff)})))
   )
:

And here is an implementation of is_solution_trivial:

is_solution_trivial:= (pde, sol::{`=`, set(`=`)})-> 
   evalb(eval(`if`(sol::set, sol, {sol}), depvars(pde)=~ 0) = {0=0}) 
:

 

I would guess that the following is a fundamental principle of engineering. I've never formally studied engineering, so I don't know whether it is. To me, it is just intuition (something that is obvious), having taking apart and rebuilt machines and other systems my entire conscious life. (I'd appreciate it if someone who knows would tell me whether it is indeed formally a fundamental principle of engineering.)

Let's say that you have two closely related systems, which I'll call W (for working) and N (for not working). They could be machines, programs, scientific theories, literary essays, biological systems, etc. So, W is working (i.e., it does what it was designed to do), but it needs to be modified so that it can do something else, or something additional. On the other hand, N has been designed and built based on W and it incorporates the needed changes, but it doesn't work.

My principle is 

  1. Junk N. Discard it. It may be disassembled and small parts re-used. Otherwise, it should be forgotten, regardless of how much effort went into it.
  2. Proceed by making small changes to W. Test after every small change to make sure that it's still working. Do not make any further changes until the current version works! This may require hundreds of small changes if you're working alone, and perhaps much more if you're working as a team.
  3. (Optional step) Ocasionally remove from W parts that are no longer needed. The smaller size will make the work proceed faster.

Now, you may protest, "But a lot of effort and/or expense went into N!" That doesn't matter; it's more efficient and/or economical to work on W. Accountants refer to this as "sunk costs"; investment experts say "Don't throw good money after bad"; professors of creative writing say "Kill you darlings". If my principle were not true, then life on Earth would likely have started independently many times. Yet all evidence suggests that it hasn't.

So, in this thread, it seems clear that you have a W program and an N program. You've been trying to correct the N program. Stop that. Work on your W program.

First 140 141 142 143 144 145 146 Last Page 142 of 395