Jarekkk

439 Reputation

13 Badges

14 years, 163 days

MaplePrimes Activity


These are answers submitted by Jarekkk

sol := [solve(w^11 = -5-5*I)]; # all solutions

# solutions with positive both real and imaginary part
sol_pos := [];
for i to nops(sol) do
  if (is(Re(sol[i]), positive) and is(Im(sol[i]), positive))
  then sol_pos := [op(sol_pos), sol[i]]
  end if
end do;

sol_pos;

 

# Now, with evalf(sol_pos); you can see which solution is the one you need, but you can also let Maple find it

f := unapply(piecewise(seq(op([x = i, sol_pos[i]]), i = 1 .. nops(sol_pos)), undefined), x):
maximize(Re(f(x)), location);

# And now it depends how you want to simplify the solution, so you can do e.g.

simplify(simplify(Re(sol_pos[1]))+I*simplify(Im(sol_pos[1])));

# Or

convert(simplify(Re(sol_pos[1])+I*Im(sol_pos[1])), exp);


# You can also see the points (all solutions) on the plot

plots[complexplot](sol, style = point, symbolsize = 15, labels = ["Re", "Im"]);

When you create the functional operator with classical arrow notation, the functional expression (the right hand side next to the arrow) is unevaluated. When you need the functional expression to be evaluated when defining the function, you have to use the unapply command.

It is nicely seen at your for-loop:

1) arrow notation

for i from 2 to 3 do
  f[i] := x -> -(D(f[i-1]))(x)/x;
end do;

          D(f[i - 1])(x)
x -> - ---------------
                x 

      
           D(f[i - 1])(x)
x -> - ----------------
                x       


2) unapply

for i from 2 to 3 do
  f[i] := unapply(-(D(f[i-1]))(x)/x,x);
end do;

       cos(x)    sin(x)
       ------ -   ------
          x            2  
                      x   
x -> - ---------------
                x       

 


           sin(x)   2 cos(x)   2 sin(x)   cos(x)   sin(x)
         - ------ - -------- + --------     ------ - ------
             x          2                 3         x         2  
                       x                 x                   x   
       - ------------------------------ + ---------------
                       x                                  2       
                                                         x        
x -> - --------------------------------------------------
                               x                         


if you use simplify as well, the result looks better:

for i from 2 to 3 do
  f[i] := unapply(simplify(-(D(f[i-1]))(x)/x),x);
end do;


       cos(x) x - sin(x)
x -> - -----------------
               3        
              x      

   
               2                        
       sin(x) x  + 3 cos(x) x - 3 sin(x)
x -> - ---------------------------------
                       5                
                      x                 


      


Look at ?rem.

For your example:

p1 := 1.87*x^3-2*x^2+5.789*x-3.2;


p2 := 1.5*x^2+2*x-1.4;

         
q := quo(p1, p2, x);


r := rem(p1, p2, x);


This

out := ArrayTools:-Concatenate(2,convert(S1,vector),convert(S2,vector),convert(S3,vector)):

can be typed using seq as

out := ArrayTools:-Concatenate(2, seq(convert(S||i, vector), i = 1 .. 3)):

so you can then only change 3 to n.


Edit: The vector command is deprecated, so you should use Vector (big initial letter) instead.

There are many typos in your post... By the way, the answers to your questions can be found as well in the help (see ?plot) as here on MaplePrimes.

There are many possibilities, just some of them (I used a simple example to demonstrate):

N:=6:

1)


A:=array([seq(0.1*i,i=1..N)]):
B:=array([seq(0.2*i,i=1..N)]):
plot(<<A>|<B>>,style=point);

2)

Av:=Vector[column]([seq(0.1*i,i=1..N)]):
Bv:=Vector[column]([seq(0.2*i,i=1..N)]):
plot(<Av|Bv>,style=point);

3)

A:=array([seq(0.1*i,i=1..N)]):
B:=array([seq(0.2*i,i=1..N)]):
plot([seq([A[i], B[i]], i = 1 .. N)],style=point);

4)

AB:=Matrix([[seq(0.1*i,i=1..N)],[seq(0.2*i,i=1..N)]]):
plot(AB^(%T),style=point);

They all give the same plot:

This really doesn't look that nice (since it is not aligned), but from what you got maybe the easiest.

rows := 4:
cols := 3:
for i to rows do
    print(seq(cat(`        `, a(), b[(rand(1 .. nops(b)))()], a(), "=_____"), j = 1 .. cols));
    print(``):
end do;

          11x10=_____,         3+11=_____,         14-15=_____

           2/13=_____,         6-13=_____,         2x8=_____

            2x1=_____,         5-3=_____,         13+2=_____

           2+15=_____,         2-15=_____,         13-5=_____

By the way, what should be the answer for 2/13 (and similar expressions like 5/9, 4/7, ...)?

I think it is caused by the variable x which is local in the procedure. You can declare x as a global variable (I don't recommend this) or you can change the returning value from your procedure to

unapply(piecewise(pw), x);

and you wil get the function immediately.

You'd better write what these commands do or show some example since I don't know how many people here are familiar with Matlab.

This is my suggestion:

thetas := 1: N := 5:
zimag := Vector(N+1, i->I*(i-1)*thetas/N);

R := Vector(N+3, i->i); # I do not know what R should be, so this is just some vector (at least N+1 size)


zreal := log~(R[1 .. ArrayNumElems(zimag)]);

z := zreal+zimag;


However, you can do it all by one command:

z := Vector(N+1, i->log(R[i])+I*(i-1)*thetas/N);


The foor loop can look like this:

for i from 1 to ArrayNumElems(z) do ... end do;

but when i goes from 1 the "from 1" part is not necessary and you also don't have to compute the number of elements in z, since you know it from the beginning. So you can type:

for i to N+1 do ... end do;

Something like this?

with(RandomTools):
l := Generate(list(float(range = -10 .. 10), 6));

[-2.89694812, -2.75731771, 3.90602788, 9.79455091, -8.11450929,  5.16968582]


l_neg := select(type, l, 'negative'); # the list of negative values in l

            [-2.89694812, -2.75731771, -8.11450929]

add(l_neg[i], i = 1 .. nops(l_neg));  # summation of negative values in l

                          -13.76877512

nops(l_neg); # the number of values in l_neg (i.e. the number of negative values in l)
                               3

For more info look at ?select, ?add, ?op.

Change

f[k] := x -> piecewise(x > 0, k, 0);

to

f[k] := unapply(piecewise(x > 0, k, 0), x);

You can use the makefrac proc.

expr:=(2*x+7)*(1/5)+(6*x-3)*(1/3);
                            12     2
                            -- x + -
                            5       5


makefrac := (``@numer)/(``@denom):
makefrac(expr);
                           (12 x + 2)
                           -----------
                                (5)    

Edit:

This is another possibility:

makefrac2 := proc(x) convert(numer(x), name)/convert(denom(x), name) end proc:
makefrac2(expr);
                             12*x+2
                             ---------
                                  5   

I am not sure what you want, but two tips:

1) Do you know how to change Component Properties of a ?SliderComponent ? It's no problem to have 0..90 there (if this is what you want). 

2) Argument of trigonometric functions must be given in radians. However, if you want to compute e.g. cos(x) where x is the number of degrees, you can compute it as cos(x*Pi/180).

You can use ?solve command and then ?assign. It could look e.g. like this:

solve([1.2000000*10^7+g[2000] = 0, g[2004] = 0, g[2111]+1.995976713*10^8 = 0, 2.00000000*10^8+g[2001] = 0]);

assign(%);


However, it has to have a unique solution. As I see in your list, there are e.g. these two equations:


I rewrote your system as (there are notation changes):

s := 10:  dT := 0.2e-1: k1 := 2.4*10^(-5):  k2 := 3*10^(-3):
N := 5: delta := .24: c := 2.4: T0 := 1:

sys :=  (D(T))(t) = s-dT*T(t) - k1*V(t)*T(t),
           (D(T2))(t) = k1*V(t)*T(t) - dT*T2(t) - k2*T2(t),
           (D(T3))(t) = k2*T2(t) - delta*T3(t),
            (D(V))(t) = N*delta*T3(t) - k1*V(t)*T(t) - c*V(t);

Then you can use the DEtools package for plotting the solutions, but I'm afraid you will not be able to plot the direction fields, since it is available only for systems with at most two dependent variables. You can read it in the description of ?DEtools[phaseportrait], ?DEtools[DEplot] or ?DEtools[dfieldplot].

And for plotting one solution (for given ics) you can use e.g.:

with(DEtools):
DEplot([sys], [T(t), T2(t), T3(t), V(t)], t = 0 .. 30, [[T(0) = T0, T2(0) = 3, T3(0) = 1, V(0) = 4]], scene = [T(t), T2(t)]);

Then you can for example use the animate=true option as well if you want to see how it progress in time...

Look at the acer's post.

1 2 3 4 5 6 7 Page 3 of 7