Kitonum

21450 Reputation

26 Badges

17 years, 47 days

MaplePrimes Activity


These are answers submitted by Kitonum


 

restart

f := proc (x) options operator, arrow; x^2+x-12 end proc

n := 10

h := 5NULL

printf("\n    i        x       f (dec.form)    f (sci. notat.)\n"); printf("  ---------------------------------------------------\n"); for i from 0 to n do X[i] := i*h; Y[i] := f(X[i]); printf(" %5d  %9.4f  %13.9f  %17.10e\n", i, X[i], Y[i], Y[i]) end do


    i        x       f (dec.form)    f (sci. notat.)
  ---------------------------------------------------
     0     0.0000  -12.000000000  -1.2000000000e+01
     1     5.0000   18.000000000   1.8000000000e+01
     2    10.0000   98.000000000   9.8000000000e+01
     3    15.0000  228.000000000   2.2800000000e+02
     4    20.0000  408.000000000   4.0800000000e+02
     5    25.0000  638.000000000   6.3800000000e+02
     6    30.0000  918.000000000   9.1800000000e+02
     7    35.0000  1248.000000000   1.2480000000e+03
     8    40.0000  1628.000000000   1.6280000000e+03
     9    45.0000  2058.000000000   2.0580000000e+03
    10    50.0000  2538.000000000   2.5380000000e+03

 

NULL

plot1 := plot([seq([X[k], Y[k]], k = 0 .. n)], style = point, symbol = soliddiamond, symbolsize = 24, color = blue)

plot2 := plot(f(x), x = 0 .. 50)

with(plots)

display([plot1, plot2])

 

NULL


 

Download Digitalize_new.mw

The following code works:

restart;
ExY := map(convert,[WPKCPYWFYWCXHY, WPKCTEYFHCFEEE, HYCYTFHYYWWKCE, HYHHTFHKFEYHEH, HKXWYHFECTFFTF, HKWEHPPECWWHTC, HKXWYTPXHFHWYP, HKFEXCTFECXFKP, HKFEYPPEEEPHYW, HYTHCCFEWPPEXX, HKXKXCKFCHTEWK, HYEKPPCKFTWXXW], string);
Blist:=map(convert,[W,P,K,C,Y,F,X,H,T,E], string); # basis letters
nWords:=numelems(ExY);
Wletters:=length(ExY[1]);
Bletters:=numelems(Blist);
A:=Matrix(Bletters,Bletters):
with(ListTools):
for iW from 1 to nWords do 
  for iL from 1 to Wletters-1 do 
     fromLett:=ExY[iW][iL]; 
     toLett:=ExY[iW][iL+1]; 
     BfromLett:=Search(fromLett,Blist);
     BtoLett:=Search(toLett,Blist);
    A[BfromLett,BtoLett]:=A[BfromLett,BtoLett]+ 1; 
  end do; 
end do; 
A;

 

1. You have chosen an extremely inefficient way to create a list. Compare two ways:

 # The first way
t:=time():
L:=[$ 1..100000]:
time()-t;

# The second way
t:=time():  
 L := []: for i from 1 to 100000 do L := [op(L), i] end do:
time()-t;


2. I do not know how to refer to the labels programmatically. But if you assign any names to your equations, for example eq1, eq2, ... , eq10 , then 

[seq(eq||i, i=1..10)];

From the link   webpage  you specified, you missed the beginning of the code, in which all parameters  (a, b, h, n, f)  were set. Here is the full code for your version (you have changed only the parameter  n ):


 

restart; Digits := 16; with(plots); a := 60.0; b := 100.0; n := 5; h := (b-a)/n; f := proc (x) options operator, arrow; evalf(20*exp(-(1/2)*((1/5)*x-78/5)^2)/sqrt(2*Pi)) end proc; printf("\n    i        x       f (dec.form)    f (sci. notat.)\n"); printf("  ---------------------------------------------------\n"); for i to n do X[i] := h*i+a; Y[i] := f(X[i]); printf(" %5d  %5.4f  %13.9f  %17.10e \n", i, X[i], Y[i], Y[i]) end do


    i        x       f (dec.form)    f (sci. notat.)
  ---------------------------------------------------
     1  68.0000    1.079819330   1.0798193303e+00
     2  76.0000    7.365402806   7.3654028061e+00
     3  84.0000    3.883721100   3.8837210997e+00
     4  92.0000    0.158309032   1.5830903166e-01
     5  100.0000    0.000498849   4.9884942580e-04

 

NULL


 

Download Adjust.mw

 

The equation  DEF_Profit1  in addition to the unknown  S  contains 3 parameters  beta, s, C. If you specify the values of these parameters, you can easily find all the roots, for example:

sol1 := solve(eval(DEF_Profit1, [beta = 3, s = 0.1, C = 2]), S);
                       
 sol1 := 0.004990229958, 29.61213284, -3.574031930, -26.04309114

 

By default, axes=normal  option works. So just remove  axes=box  option from your code:

plot(sin(x), x=0..2*Pi);


Addition.
 If you want the boxed effect and that the tickmarks are on the line  y=0 , then do so:

plots:-display(plot(sin(x), x=0..2*Pi), plot([[0,-1],[2*Pi,-1],[2*Pi,1],[0,1]], color=black));
                

Edit.         

If you do not have additional information about the parameters  chi, lambda1, lambda2, phi, psi, rho, you can simply use  simplify  command:

with(LinearAlgebra):

A:=Matrix([[phi,conjugate(psi),chi,conjugate(rho)],[psi,-conjugate(phi),rho,-conjugate(chi)],[lambda1*phi,conjugate(lambda1)*conjugate(psi),lambda2*chi,conjugate(lambda2)*conjugate(rho)],[lambda1*psi,-conjugate(lambda1)*conjugate(phi),lambda2*rho,-conjugate(lambda2)*conjugate(chi)]]);
indets(A, name);
Determinant(A);
simplify(%);
                           

 
 

Try  colorscheme  option for curves. An example:

restart;
plots:-spacecurve([cos(t), sin(t), 0.3*t], t=0..4*Pi, colorscheme=[blue, green], thickness=3, axes=normal);

                            

Unfortunately, this does not work when solving differential equations with numeric option (plotting by  plots:-odeplot  command). In this case, use a workaround as below (the same curve as above):

restart;
sol:=dsolve({diff(x(t),t)=-sin(t), diff(y(t),t)=cos(t),diff(z(t),t)=0.3, x(0)=1,y(0)=0,z(0)=0}, numeric):
plots:-pointplot3d([seq(eval([x(t),y(t),z(t)],sol(i)), i = 0..12.56,0.2)], colorscheme = [blue, green], style = line, thickness=3, axes=normal);

 

 

You can specify  g(x)  as a piecewise-function and then use in any calculations, for example:

f(x):=x+1;
g(x):=piecewise(x<>2,(x+1)*(x-2)/(x-2), x=2,undefined);
simplify(f(x)*(g(x)+1));
limit(g(x), x=2);
diff(g(x), x);
int(g(x), x=1..3);
discont(g(x), x);
                                   

 

 

With  for  loop:

restart;
r:=rand(1..100):
k:=0:
for i from 1 to 20 do
L[i]:=r();
if type(L[i], even) then k:=k+1; L1[k]:=L[i] fi;
od:
L:=convert(L, list);
L1:=convert(L1, list);
`+`(L1[])/nops(L1);


It is easier to do this in another way:

restart;
r:=rand(1..100):
L:=[seq(r(), i=1..20)];
L1:=select(t->type(t, even), L);
`+`(L1[])/nops(L1);

If you want new random numbers to be generated with each call, then insert the  line  randomize():  after restart;

Programmatically, I found only a method using  plots:-textplot  command:

plots:-textplot([[-0.1,0, max,font=[times,bold,20]], [0.1,0, f(x),font=[times,20]], [0,-0.1, x in [2,3]]], size=[140,60], axes=none);
                                                              

 

 

1. Conversion to  Matrix  can be easier (see the code below).

2. I agree that this piece "A particular solution of the system can be then written in the form   F(t) = S(t) C0 + P(t)  where  C0 is  n by 1 and  F(0) = C0 + P(0)." of Help is incorrect.

3. The constants  C1  and  C2  for the particular solution with the specified initial conditions  x0  can be obtained as follows (first we find the general solution  x ):

restart;
A:=Matrix(2, 2, [1, 4, 5, 1]);
x0:=Vector([2,1]);
#initial condition
sol := DETools:-matrixDE(A, t);
M:=convert(sol[1], Matrix);  
#convert to Matrix
x:=M.<C1,C2>;  # C1 and C2 are arbitrary constants
solve(eval(convert(x=~x0,list),t=0), [C1,C2])[];
simplify(eval(x, [%[],t=0]));
# The check

 

dice := proc()
    local r;
    r:=rand(1..6);
    'r'()$2;
end proc:

Example of use:
seq([dice()], i=1..10);
           
 [6, 5], [3, 1], [5, 2], [3, 2], [2, 4], [3, 3], [1, 2], [5, 4], [5, 6], [2, 3]


 

The code below finds 2 chains:

chosen1 := [[1,2],[1,20],[3,4]]:
chosen2 := [[2,3],[20,3],[3,4]]:
chosen3 := [[3,4],[5,7]]:
chosen4 := [[4,5],[5,6]]:
chosen5 := [[5,6],[7,9]]:
seq(seq(seq(seq(seq(`if`(i[2]=j[1] and j[2]=k[1] and k[2]=l[1] and l[2]=m[1], [i,j,k,l,m], NULL), m=chosen5), l=chosen4), k=chosen3), j=chosen2), i= chosen1);
                     
 [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],  [[1, 20], [20, 3], [3, 4], [4, 5], [5, 6]]
 

Addition.  If there are many source lists, then the process of building nested sequences can be automated using the procedure  NestedSeq  that can be found in this thread.

because

evalc(cos(I*x));  # This assumes that x is real
convert(%, exp);
                                               
cosh(x)
                                     (1/2)*exp(x)+(1/2)*exp(-x)

First 106 107 108 109 110 111 112 Last Page 108 of 289