Joe Riel

9530 Reputation

23 Badges

20 years, 29 days

MaplePrimes Activity


These are answers submitted by Joe Riel

Why not just compute the cost for one year of usage?

Fluorescent = ($3.67)*4 + (13*W)*(4*hr/day)*(365*day)*(0.151e-3*dollar/W/hr) = $17.55
Incandescent = (3.29)/2  + (40*W)*(4*hr/day)*(365*day)*(0.151e-3*dollar/W/hr) = $10.46

It works fine here, in command line and in the Standard worksheet, both with 1D and 2D input.  Note that delta=1 does not result in alpha*t but rather alpha + t.

Consider trying fsolve.  For example,

f := exp(-x^2*sin(x)):
F := Int(f, x=0..b):
fsol := fsolve(F = 1/2, {b});
                                                       fsol := {b = 0.5166551554}
# check the result
evalf(eval(F, fsol));
                                                              0.5000000000


Here's a different approach.  It uses A[[i,j,k]] to select indices i,j,k from list (or set) A.

A:=[5,0,1,0,0]:
C:=[0.735,0,0.265,0,0]:
nonZeroIndices := [seq(`if`(A[i]=0,NULL,i), i=1..nops(A))];
                           nonZeroIndices := [1, 3]

A[nonZeroIndices];
                                    [5, 1]

C[nonZeroIndices];
                                [0.735, 0.265]

It would help if you didn't run separate equations together.  Punctuation can improve clarity.  I don't see how you came up y1=y1+/-exp(t*siga).

I found a site, www.mathcurve.com/fractals/gosper/gosper.shtml, that shows how to construct the base curve.  Here is an update that gives the precise curve. This can be cleaned up, but I took the easy route from what I'd already done.

recursive := proc(s::list, f::list, c::list, depth::posint)
local z,seg,segs;
    segs := seq(map(Transform, z, s, f), z in c);
    if depth = 1 then
        segs[];
    else
        seq(procname(seg[],c,depth-1), seg in segs)
    end if;
end proc:

Transform := proc(z,s,f)
local x,y,x2,y2,mag,theta;
    (x,y) := op(f-s);
    mag := sqrt(x^2+y^2);
    theta := arctan(y,x);
    x2 := z[1]*cos(theta) - z[2]*sin(theta);
    y2 := z[1]*sin(theta) + z[2]*cos(theta);
    [s[1] + mag*x2, s[2]+mag*y2];
end proc:

# Generate points of base curve
V := [seq([cos,sin](k*Pi/3), k=0..6)]:
E := [seq(V[k+1]-V[k], k=1..6)]:

P[1] := [0,0]:
P[2] := P[1]+E[5]+E[6]:
P[3] := P[2]+E[1]+E[6]:
P[4] := P[3]+E[3]+E[2]:
P[5] := P[4]+E[1]+E[2]:
P[6] := P[5]+E[5]+E[6]:
P[7] := P[6]+E[5]+E[6]:
P[8] := P[7]+E[5]+E[4]:

# Compute point (x,y) which is used to transform
# P[8] to (1,0); that is needed by Transform.

eqs := normal(Transform(P[8], P[1], [x,y]));
sol := solve({eqs[1]=1,eqs[2]=0}, {x,y});
xy := eval([x,y],sol);

# Apply Tranform to vertices
Q := map(Transform, [seq(P[k], k=1..8)], P[1], xy);

# Generate the Peano-Gosper curve
flowsnake := recursive([0,0],[1,0]
                       , [NULL
                          , [Q[1],Q[2]]
                          , [Q[3],Q[2]]
                          , [Q[4],Q[3]]
                          , [Q[4],Q[5]]
                          , [Q[5],Q[6]]
                          , [Q[6],Q[7]]
                          , [Q[8],Q[7]]
                         ]
                       , 3
                      ):

plot([flowsnake],axes=none,scaling=constrained);

Here's one approach.  I only approximated the shape, so you'll have to clean up

recursive := proc(s::list, f::list, c::list, depth::posint)
local z,seg,segs;
    segs := seq(map(Transform, z, s, f), z in c);
    if depth = 1 then
        segs[];
    else
        seq(procname(seg[],c,depth-1), seg in segs)
    end if;
end proc:

Transform := proc(z,s,f)
local x,y,x2,y2,mag,theta;
    (x,y) := op(f-s);
    mag := sqrt(x^2+y^2);
    theta := arctan(y,x);
    x2 := z[1]*cos(theta) - z[2]*sin(theta);
    y2 := z[1]*sin(theta) + z[2]*cos(theta);
    [s[1] + mag*x2, s[2]+mag*y2];
end proc:

# These are just a crude approximation

P0 := [0,0]:
P1 := [.3, -.125]:
P2 := [.60,  .125]:
P3 := [.2,   .250]:
P4 := [.15,  .60]:
P5 := [.575,  .5]:
P6 := [0.9,  .40]:
P7 := [1,     0]:

flowsnake := recursive([0,0],[1,0]
                       , [NULL
                          , [P0,P1]
                          , [P2,P1]
                          , [P3,P2]
                          , [P3,P4]
                          , [P4,P5]
                          , [P5,P6]
                          , [P7,P6]
                         ]
                       , 2 # increase to refine
                      );

plot([flowsnake],axes=none,scaling=constrained);

The coeff procedure works on algebraic expressions, not equations.  Try coeff(lhs(functie3),t3,2). 

Maybe you can give an example.  The function sscanf would be useful mainly if you had to parse strings, is that the case?

How many conditions do you expect the piecewise to have?  The piecewise is not particularly efficient with lots of conditions (they are evaluated sequentially).

You might want to arrange the conditions to implement a binary search, which will make the average evaluation time O(lg(n)) rather than O(n).  That will require nested piecewises.  Here is one way to do that (creating new matrices isn't the best technique, but it is easy to implement):

dataToPW := proc(M :: Matrix, x::name, $)
local m, j;
description "create nested piecewise expression that represents the data in M";
    # This assume M is sorted in its first column
    m := op([1,1],M);
    if m=1 then
        return M[1,2];
    else
        j := iquo(m,2);
        return piecewise(x <= M[j,1]
                         , procname(M[1..j, ..], x)
                         , procname(M[j+1..,..], x)
                        );
    end if;
end proc:

n := 8:
data := Matrix([seq([i,i^2], i=1..n)]):
PW := dataToPW(data, x);
             { { { 1         x <= 1
             { { {                             x <= 2
             { { { 4        otherwise
             { {                                                x <= 4
             { { { 9          x <= 3
             { { {                            otherwise
             { { { 16        otherwise
       PW := {
             { { { 25         x <= 5
             { { {                             x <= 6
             { { { 36        otherwise
             { {                                               otherwise
             { { { 49         x <= 7
             { { {                            otherwise
             { { { 64        otherwise

The plotting is easy enough.  As you surmised, implicitplot3d will do the job:

plots:-implicitplot3d(z^2=1-(r-5)^2, r = 0..7, theta = 0..2*Pi, z = -3..3, coords = cylindrical);

The first argument has to be a procedure.  Also, the conditional has the else last. Finally, the operator arrow has one hyphen, not two.  I'm still not sure what you want, but the following is closer:

z -> if Re(z) >=0 then evalb(Im(z) > 0) else evalb(Re(z)=0) end if

 

Remove all the with(linalg) calls.  linalg is old and doesn't work with Matrices.  Never use with inside a procedure, it won't work properly there.

Using * to multiply Matrices doesn't work, use either the dot operator (.), or procedure calls (see LinearAlgebra).

To call a procedure you have to append parentheses.  For example, in Step4 change Print to Print();

Does A contain sublists?  Rather than convert, try

Array(1..nops(A), A);

Note also that this returns an Array, not an array.  The latter is an older Maple structure.

There are a few problems with this.  First, the if functions are evaluated immediately.  Second, the conditions of the if's are expressed as equalities, which will not work. The independent variable (t) is continuous, as such it makes no sense numerically to compare it to any value.  You should use inequalities (t<=0, t<=1, t<=2, t<=3). Third, the differential equation has the parameters b, c, and n, which are undefined.  Probably they are meant to be functions of e and f.

You can express the if's using the piecewise function.  Here is one approach; I arbitrarily reassigned b, c, and n:

a := .178131:

pw := piecewise(t <= 1, 6, t <= 2, 10, t <= 3, 15, 20):

e := -0.6814e-1*pw:
f := 0.16242e-1*pw^(1.5):

# Arbitrary assignments
n := 2:
b := e:
c := f:

dsys := [diff(Log10S(t), t) = -(a+b+c)*n*(-Log10S(t)/(a+b+c))^((n-1)/n), Log10S(0) = -0.1e-3]:
integ := dsolve(dsys, numeric):
integ(6);
                    [t = 6., Log10S(t) = -4.28489796949036]

Easier might be

(**) ans:=solve(x^4=16,{x});
                ans := {x = 2}, {x = -2}, {x = 2 I}, {x = -2 I}

(**) subs(x=m, [ans]);
                  [{m = 2}, {m = -2}, {m = 2 I}, {m = -2 I}]

First 70 71 72 73 74 75 76 Last Page 72 of 114