Joe Riel

9530 Reputation

23 Badges

20 years, 23 days

MaplePrimes Activity


These are answers submitted by Joe Riel

Here's a procedure that does what you want. Note, however, that using piecewise with a lot of conditions (100 in your case) is not very efficient. You would be better off generating a procedure that uses a binary search on the front end to select the appropriate interval.
makePW := proc(M::Matrix)
local m,n,x,r,c;
    (m,n) := op(1,M);
    unapply(piecewise(seq( [M[r,-2] < x and x <= M[r,-1], add(M[r,c]*x^(c-1), c=1..n-2)][]
                           , r = 1..m))
            , x);
end proc:
Read the ?Digits help page. The Digits environmental variable controls how many digits are used when doing software-based floating-point computation.
1.0000000005 - 1 ;
                                     0.
Digits := 20;
                                     20
1.0000000005 - 1 ;
                                       -10
                                   5 10   
Specify the range to fsolve to restrict the solution to positive values. For example,
y := -x^3-2*x^2+3*x+5;
fsolve(y, x = 0 .. infinity);
                                 1.651093409
fsolve(y, x = -infinity .. 0);
                         -2.377202854, -1.273890555
Note that with the D operator the conditional in unnecessary, that is, (D@@0)(f)(x) = f(x). However, I find the following clearer
n2 := proc(l::nonnegint)
local z,f;
    if l=0 then
        f := -cos(z)/z;
    else
        f := -(-1)^l*diff(cos(z)/z,z$l);
    end if;
    unapply(f,z);
end proc:
Occasionally I've wished that diff were extended so that diff(f,x,n), with n a nonnegint, was equivalent to diff(f,x$n), and diff(f,x,0) returned f. Then the conditional could be removed and we'd have
n2 := proc(l::nonnegint)
local z;
    unapply(-(-1)^l*diff(cos(z)/z,z,l), z);
end proc:
which is concise and clear.
Use evalf to numerically evaluate the integral:
evalf(iL_waveform_func_RMS_AVG(Ue_input,Ua_input,Ia_input,L_input,T_input,3,RMS));
                                         31.25185185
When you specify the avoid option, you should also specify a start option, so that the search doesn't get trapped. See the comments on 'avoid' in the Optional Arguments subsection of ?dsolve,details. In this case,
fsolve('Y1'(t)=Yeq, t=1, avoid={t=T1});

                                0.5225499740
Here's one approach
> y := (a/b)^(3/2)*(c*d*e/f*g*h)/(i/j)^(3/2)*(k*l*m/n*o*p);
                                   3/2
                            4 (a/b)    d e g h k l m o p
                       y := ----------------------------
                                           3/2
                                    f (i/j)    n

> vars := indets(y,name) minus {a,b,i,j};
                   vars := {e, f, p, d, k, n, g, l, m, o, h}

> fy := unapply(y, sort(convert(vars,list)));
                                                      3/2
                                               4 (a/b)    d e g h k l m o p
    fy := (d, e, f, g, h, k, l, m, n, o, p) -> ----------------------------
                                                              3/2
                                                       f (i/j)    n

> data := LinearAlgebra:-RandomMatrix(11,11,generator=0..1.0):
> for col to 11 do fy(convert(data[1..-1,col],list)[]) end do;

                                               3/2
                            0.02545310970 (a/b)
                            ----------------------
                                        3/2
                                   (i/j)
...
Naturally you wouldn't use a random Matrix. Also, I assume you'll preassign the parameters a, b, i, and j. By the way, you probably don't want to use `I' as a variable. Maple uses it as the complex unit. While you can use D, it is assigned the differential operator and protected. That isn't a problem here, since you don't have to directly assign to it, but its probably best to avoid it; that's why I used lower case for the variable names.
Try LinearAlgebra:-Equal.
See the MaplePrime forum factoring integer coefficients.
sum is for symbolic summations, not discrete additions. Use add and all is well. To plot a discrete sequence, you could convert it to a list and do
pts := ListTools:-Enumerate(list_of_vals):
plots[pointplot](pts);
Calling plot(pts) also works, but connects the dots.
Use Mariner's suggestion:
u_dot := subs(losning, diff(y(x),x));
                           proc(x)  ...  end;
u_dot(1);
                           0.000789699102393688408
I don't understand what you want. Do you have a procedure that is running (possibly for too long), want to stop it, but at the same time access an intermediate computation? One possibility is to use the Maple timelimit. For example:
unending := proc() global i; for i do NULL end do: end proc:
timelimit(1,unending()):
Error, (in unending) time expired
i;
                                   849323
Better would be to use a try/catch statement:
try 
    timelimit(1,unending());
catch "time expired":
    printf("count = %d\n", i);
end try;
count = 1050739
Use plots[odeplot]:
plots[odeplot](`løsning`, [x,diff(y(x),x)], 0..10);
Rather than using sum, in this application, where the sum is over a finite, explicit sequence of values, it is usually better to use add. However, to better understand what is happening (if that isn't now apparent), you could use seq to see the sequence of terms to be summed. Thus
seq(piecewise(n<1,0,n),n=0..7);
                            0, 1, 2, 3, 4, 5, 6, 7
seq(piecewise(n<8,0,n),n=0..7);
                            0, 0, 0, 0, 0, 0, 0, 0
The return value of a procedure is normally the last thing that was computed (more or less). The 9 is the value that was assigned to s[i], the (true,true) is the value that was assigned to (HighestGroup,`done`). If you want the procedure to return nothing, make the last statement NULL.
First 105 106 107 108 109 110 111 Page 107 of 114