Joe Riel

9530 Reputation

23 Badges

20 years, 26 days

MaplePrimes Activity


These are answers submitted by Joe Riel

This isn't generally possible; the zeros of the numerator are the problem.  You can use two equations, d(x) = u, y = p(x,u), where d(x) is a differential expression in x(t) and p is an algebraic equation in x(t) and u(t).  Consider, for example, the simpler G = Y/U = s/(s+1).  You can represent that as

diff(x(t),t) + x(t) = u(t)
y(t) = -x(t) + u(t)

Change the ?sum to an ?add and remove the forward quotes.

You can use ?evalc to evaluate this.  Note that ?Re and ?Im are the real and imaginary operators, respectively. Let's introduce inert functions re and im for the real and imaginary parts of a complex.  Then

cmplx := z -> re(z) + I*im(z):
Hz := cmplx(H);
                             Hz := re(H) + im(H) I

Ez := cmplx(E);
                             Ez := re(E) + im(E) I

evalc(Re(Ez*conjugate(Hz)));
                           re(E) re(H) + im(E) im(H)

x := g(t,s):
y := h(t,s):
A := f(x,y):
diff(A,t$4);

The output is a bit complicated.  Here is the first derivative, which is considerably shorter

diff(A,t);
                              /d         \                             /d         \
    D[1](f)(g(t, s), h(t, s)) |-- g(t, s)| + D[2](f)(g(t, s), h(t, s)) |-- h(t, s)|
                              \dt        /                             \dt        /

D[1](f) means the partial derivative of f with respect to the first argument (here, x).

To obtain a more compact display, consider using ?PDEtools[declare]:

PDEtools:-declare(g(t,s),h(t,s)):
diff(A,t);
                        D[1](f)(g, h) g[t] + D[2](f)(g, h) h[t]



I don't understand the equations with nu and the conditional.  Disregarding that, you could do

params := { h = 6.6e-34, c = ..., T=..., etc }:
B := 2*h*ν3/(c2 *(exp(h*ν/k/T)-1):
plot(eval(B, params), nu=1..10);

Rather than starting a new thread it is generally better to continue the old.  Regardless, a few comments.

My suggestion to use ?add instead of ?sum was incomplete.  The forward quotes which you used are not needed and not appropriate when using add.  A more serious problem is that you are using the name of the procedure (f), in the procedure.  While Maple can recurse, the recursion must eventually halt, and there is nothing in the procedure that does that.  The real problem is that you want f[1] to be a different procedure than f.  Alas, Maple treats them as the same.  For example

f := x -> f[1](x):
f(3);
Error, (in f[1]) too many levels in recursion

It isn't clear why you are calling f[1](x).  Is that supposed to be a completely inert call.  In that case, you would be better naming it as f1. That is, you could do

N := 2:
f := eta -> add(cat('f',i)(eta)*m^i, i=0..N):
f(3);
                                                       2
                              f0(3) + f1(3) m + f2(3) m


B1 is a list, not a vector.  One way to enter a vector is to use angle brackets: 

B1 := <1,2,0,-1>:

It took a little doing to reproduce that error.  To do so, I had to use the (Maple 15) GUI, enter the statement (f(eta) := ...) in a 2D input, and select the "remember table assignment" option when the 2D parser opened a dialog. You probably don't want to do that; either make f a procedure

f := eta -> ...

or chose a name for the lhs of the assignment. Also, rather than sum, you should be using ?add.

Use ?dsolve,numeric. Check the output option. Here is a simple example

deq := diff(x(t),t) + x(t) = sin(t):
dsol := dsolve({deq,x(0)=0}, numeric, 'output=listprocedure'):
xt := eval(x(t), dsol):
plot(xt, 0..1);

Try ?fprintf, with the %q format if you want to include the commas

for j to 5 do
   file := sprintf("P%d.dat", j);
   fprintf(file, "%q\n", op(P[j]));
   close(file);
end do:

One way to do this is to generate the partitions in reverse-lexicographic order.  For example, the partitions of 10 are then

7,3
7,1,1,1
5,5
5,3,1,1
5,1,1,1,1,1
3,3,3,1
3,3,1,1,1,1
3,1,1,1,1,1,1,1

The following does that, but the code is rather ugly and specific to this particular problem. I threw this together without a lot of thought (it shows).
A better approach is to create an iterator that uses an Array as the data structure and each call updates it with the next partition.

Partition := proc( n :: posint)
local A,P,mx,p,psum;
    P := [Part(n,7)];
    for i do
        if member(1,P,'p') then
            p := p-1;
        else
            p := numelems(P);
        end if;
        mx := P[p]-2;
        P := (op(1..p-1,P),mx);
        psum := `+`(P);
        P := [P, Part(n-psum, mx)];
        A[i] := P;
        if P :: list(1) then break; end if;
    end do;
    return [seq(A[i],i=1..i)];
end proc:


Part := proc(n :: posint, mx :: posint)
local psum,i,A,val;
    psum := n;
    for i while psum > 0 do
        for val from mx to 1 by -2 while val > psum do end do;
        psum := psum - val;
        A[i] := val;
    end do;
    return seq(A[i], i=1..i-1);
end proc:
Partition(12);
[[7, 3, 1, 1], [7, 1, 1, 1, 1, 1], [5, 5, 1, 1], [5, 3, 3, 1],
    [5, 3, 1, 1, 1, 1], [5, 1, 1, 1, 1, 1, 1, 1], [3, 3, 3, 3],
    [3, 3, 3, 1, 1, 1], [3, 3, 1, 1, 1, 1, 1, 1],
    [3, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]


CodeTools:-Usage(Partition(100)):
memory used=15.23MiB, alloc change=0 bytes, cpu time=120.00ms, real time=119.00ms
CodeTools:-Usage(Partition(200)):
memory used=178.39MiB, alloc change=41.49MiB, cpu time=2.70s, real time=2.71s

While not efficient in that it first generates all partitions, you could do

select(type, combinat:-partition(n), list({1,3,5,7}));

To workaround a deficiency in plots:-dualaxisplot, for which I'll submit an SCR, call Plot:-DualAxisPlot instead. For example,

plotsetup('ps'):
Plot:-DualAxisPlot(sin(x),cos(x),x=0..2*Pi);

will generate a postscript file with a dual axis plot.

 

Here is the fixed worksheet, Projektet-fixed.mw.  A few months ago I posted a Maple procedure to remove bad characters from a worksheet. Here it is again, with a small correction (added call to ?fclose to close the file after writing). It was used to fix the worksheet.

DeleteBadCharacters := proc(file :: string)
local base, badchar, char, cnt, msg, outfile, str, unicode;
    str := FileTools:-Text:-ReadFile(file);
    for cnt from 0 do
        try
            XMLTools:-ParseString(str);
            break;
        catch "An invalid XML character":
            msg := lastexception[2];
            if not StringTools:-RegMatch("Unicode: 0x([^)]+)", msg, 'all', 'unicode') then
                error;
            end if;
            unicode := sscanf(unicode,"%x");
            char := convert(unicode,'bytes');
            badchar[cnt+1] := char;
            str := StringTools:-SubstituteAll(str, char, "");
        end try;
    end do;

    if cnt=0 then
        printf("no errors in file\n");
    else
        if not StringTools:-RegMatch("^(.*)\\.mw$", file, 'all', 'base') then
            error "problem extracting basename";
        end if;
        printf("deleted bad characters: %A\n", {seq(badchar[cnt],cnt=1..cnt)});
        outfile := sprintf("%s-fixed.mw", base);
        FileTools:-Text:-WriteString(outfile, str);
        fclose(outfile);
        printf("wrote updated file to %s\n", outfile);
    end if;
    return NULL;
end proc:

Update

Modified routine to print the unique bad characters deleted (rather than just the number).  With the given worksheet, the bad characters were ^U and ^V.

Consider

piecewise(l<1, c(0), c(0)+sum(c(j)^2,j=1..l-1));
First 44 45 46 47 48 49 50 Last Page 46 of 114