[go: up one dir, main page]

Items tagged with seq

Feed App Center

Dear all, how can I simplify the following command by using nested SEQ?

tagsCornersPlot := textplot3d([[seq(cornerPoints[1 .. dim, 1]), cornerPoints[1 .. dim, 1]], [seq(cornerPoints[1 .. dim, 2]), cornerPoints[1 .. dim, 2]], [seq(cornerPoints[1 .. dim, 3]), cornerPoints[1 .. dim, 3]], [seq(cornerPoints[1 .. dim, 4]), cornerPoints[1 .. dim, 3]]], align = {above, right}, font = [Courier, bold, 20])

As I assumed 'n' and 'm' are real, eta is complex. But still, there is a bar on these discrete independent variables. Secondly, the substitution of (8) applies in some terms of 'r2', and the remaining terms remain as is it.

restart

with(LinearAlgebra); with(PDEtools); with(plots); with(LREtools)

setup(mathematicalnotation = true)

setup(mathematicalnotation = true)

(1)

assume(n::real); assume(m::real)

A := proc (n, m) options operator, arrow; Matrix([[eta*phi(n, m), conjugate(eta)*conjugate(psi(n, m))], [phi(n, m), conjugate(psi(n, m))]]) end proc; Adet := Determinant(A(n, m))

eta*phi(n, m)*conjugate(psi(n, m))-conjugate(eta)*conjugate(psi(n, m))*phi(n, m)

(2)

B := proc (n, m) options operator, arrow; Matrix([[phi(n, m), conjugate(psi(n, m))], [-psi(n, m), conjugate(phi(n, m))]]) end proc; Bdet := Determinant(B(n, m))

phi(n, m)*conjugate(phi(n, m))+conjugate(psi(n, m))*psi(n, m)

(3)

r := Adet/Bdet

(eta*phi(n, m)*conjugate(psi(n, m))-conjugate(eta)*conjugate(psi(n, m))*phi(n, m))/(phi(n, m)*conjugate(phi(n, m))+conjugate(psi(n, m))*psi(n, m))

(4)

p := {eta = 1+I, phi(n, m) = (1+I*a*eta)^n*(1+I*b*eta^2)^m, psi(n, m) = (1-I*a*eta)^n*(1-I*b*eta^2)^m, conjugate(eta) = 1-I, conjugate(phi(n, m)) = (1-I*a*conjugate(eta))^n*(1-I*b*conjugate(eta)^2)^m, conjugate(phi(n, m)) = (1+I*a*conjugate(eta))^n*(1+I*b*conjugate(eta)^2)^m}

{eta = 1+I, phi(n, m) = (1+I*a*eta)^n*(1+I*b*eta^2)^m, psi(n, m) = (1-I*a*eta)^n*(1-I*b*eta^2)^m, conjugate(eta) = 1-I, conjugate(phi(n, m)) = (1-I*a*conjugate(eta))^n*(1-I*b*conjugate(eta)^2)^m, conjugate(phi(n, m)) = (1+I*a*conjugate(eta))^n*(1+I*b*conjugate(eta)^2)^m}

(5)

r1 := simplify(subs(p, r))

(2*I)*(1+I*a*eta)^n*(1+I*b*eta^2)^m*conjugate((1-I*a*eta)^n*(1-I*b*eta^2)^m)/((1+I*a*eta)^n*(1+I*b*eta^2)^m*(1-I*a*conjugate(eta))^n*(1-I*b*conjugate(eta)^2)^m+abs(-1+I*a*eta)^(2*n)*abs(I*b*eta^2-1)^(2*m))

(6)

r2 := 1-I*delta(r1, n)

1-I*((2*I)*(1+I*a*eta)^(n+1)*(1+I*b*eta^2)^m*conjugate((1-I*a*eta)^(n+1)*(1-I*b*eta^2)^m)/((1+I*a*eta)^(n+1)*(1+I*b*eta^2)^m*(1-I*a*conjugate(eta))^(n+1)*(1-I*b*conjugate(eta)^2)^m+abs(-1+I*a*eta)^(2*n+2)*abs(I*b*eta^2-1)^(2*m))-(2*I)*(1+I*a*eta)^n*(1+I*b*eta^2)^m*conjugate((1-I*a*eta)^n*(1-I*b*eta^2)^m)/((1+I*a*eta)^n*(1+I*b*eta^2)^m*(1-I*a*conjugate(eta))^n*(1-I*b*conjugate(eta)^2)^m+abs(-1+I*a*eta)^(2*n)*abs(I*b*eta^2-1)^(2*m)))

(7)

exp_expr := subs({(1+I*b*eta^2)^m = exp(I*eta^2*t)}, r2)

1-I*((2*I)*(1+I*a*eta)^(n+1)*exp(I*eta^2*t)*conjugate((1-I*a*eta)^(n+1)*(1-I*b*eta^2)^m)/((1+I*a*eta)^(n+1)*exp(I*eta^2*t)*(1-I*a*conjugate(eta))^(n+1)*(1-I*b*conjugate(eta)^2)^m+abs(-1+I*a*eta)^(2*n+2)*abs(I*b*eta^2-1)^(2*m))-(2*I)*(1+I*a*eta)^n*exp(I*eta^2*t)*conjugate((1-I*a*eta)^n*(1-I*b*eta^2)^m)/((1+I*a*eta)^n*exp(I*eta^2*t)*(1-I*a*conjugate(eta))^n*(1-I*b*conjugate(eta)^2)^m+abs(-1+I*a*eta)^(2*n)*abs(I*b*eta^2-1)^(2*m)))

(8)

``

NULL

NULL

NULL

plot3d(abs(exp_expr), n = -5 .. 5, t = -5 .. 5, eta = 1+I)

Error, (in plot3d) unexpected option: eta = 1+I

 
 

Download soldis.mw

It seems that applyrule cannot handle variable numbers of arguments, and I cannot use something like 

applyrule(f(u::anything, v::seq(anything)) = g(v, u), [f(x, y, z), f(x, y, z, t)]);
 = 
                  [f(x, y, z), f(x, y, z, t)]

Strangely, Maple does support the identical patterns in parameter declarations: 

eval([f(x, y, z), f(x, y, z, t)], f = ((u::anything, v::seq(anything)) → g(v, u)));
 = 
                  [g(y, z, x), g(y, z, t, x)]

So the two designs do not appear coherent. Should this be regarded as a "bug" in a sense? 

Of course there is no need to use the  modifier; here it is enough to use 

evalindets([f(x,y,z),f(x,y,z,t)],'specfunc'(anything,f),w->g(op(2..(),w),op(1,w))):
use f = MakeFunction('g(args[2 .. ], args[1])') in [f(x, y, z), f(x, y, z, t)] end:
use f = unapply('g(_rest, _w)', [_w::anything]) in [f(x, y, z), f(x, y, z, t)] end:

But the problem is, why is there such inconsistency described above? 

Here is a toy example

L:=<<1 | 2 | 3>; <4 | 5 | 6>>; 
(L[1,2], L[2,3]):=(0 $ 2):

As expected, L now equals <<1 | 0 | 3>; <4 | 5 | 0>>

Now I want to make a bulk assigment with the use of seq operator

(seq('L'[q,  q+1] , q=1..2)) := (0 $ 2);

but it fails. Nevertheless

seq('L'[q,  q+1] , q=1..2)

works as needed and returns unevaluated L[1,2], L[2,3]

For the t output I need to show 1, 1.2, 1.4....2, my attempt is highlighted in green below

Can anyone assist please?

#Clear memory and load packages.
restart;
with(plots):
with(Statistics):

#Define vectors and variables.
actual:=<2,3.5136,5.8016,9.1136,13.7376,20>:
t:=<1,1.2,1.4,1.6,1.8,2>:
n:=6:
RMSE:=0:

#Perform a simple linear regression on the data.
P:=LinearFit([1,x],t,actual,x);

#Display the model errors.
printf("t    Actual P  Model P  Error\n");
for i from 1 to n do
   model:=subs(x=t[i],P):
   err:=actual[i]-model:
   RMSE:=RMSE+err^2:
   printf("%2d %7.4f% 10.4f% 9.4f\n",(i+(1/5)),actual[i],model,err);
end do:

#Display the root mean square error.
RMSE:=sqrt(RMSE/n);

#Plot the points and the model.
p1:=plot(t,actual,style=point,view=[0..7,8..26]):
p2:=plot(P,view=[0..7,8..26]):
display(p1,p2);

-HFloat(17.540266666666668)+HFloat(17.712)*x

 

t    Actual P  Model P  Error

 

Error, (in fprintf) integer expected for integer format

 

HFloat(0.7463867411787324)

 

 

NULL

Download Asst_4_Question_1f.mw

If I understand right, the form  is equivalent to  (where the optional index variable is omitted), which produces a sequence of n occurrences of y. But how to explain the following output (of p1())? 

restart;

kernelopts(version)

`Maple 2023.0, X86 64 WINDOWS, Mar 06 2023, Build ID 1689885`

(1)

p0 := proc()
    local a := 1, b := 2;
    seq('assign(('a', 'b') = (a + 1, 2*b))', 1 .. 3);
    print(a, b)
end:

p1 := proc()
    local a := 1, b := 2;
    seq('assign(('a', 'b') = (a + 1, 2*b))', 3);
    print(a, b)
end:

p2 := proc()
    local a := 1, b := 2;
    'assign(('a', 'b') = (a + 1, 2*b))' $ 3;
    print(a, b)
end:

p3 := proc()
    local a := 1, b := 2;
    to 3 do
        assign(('a', 'b') = (a + 1, 2*b))
    od;
    print(a, b)
end:

p0()

p1()

p2()

p3()

4, 16

 

5, 32

 

4, 16

 

4, 16

(2)


Download singular_behaviour_of_`seq`.mw

Main code: 

p1 := proc()
    local a := 1, b := 2;
    seq('assign(('a', 'b') = (a + 1, 2*b))', 3);
    print(a, b)
end:
p1():

I learned about Dodgson calculation of the determinant only recently (https://en.m.wikipedia.org/wiki/Dodgson_condensation).
I am only interested in symbolic expressions of the determinant.
Furthermore, I compared several methods. Not surprisingly, the build in method is the fastest. But why is the seq method slower than the proc method for the Dodgson method? Is there anything I could do to program it more efficiently?
 

restart; with(LinearAlgebra)

with(combinat); with(GroupTheory)

DetDef := proc (A) local i, n, sigma; description "Jeremy Johnson. Downloaded from https://www.cs.drexel.edu/~jjohnson/2016-17/winter/cs300/lectures/determinant.mw"; n := RowDimension(A); add(PermParity(Perm(sigma))*mul(A[i, sigma[i]], i = 1 .. n), `in`(sigma, permute([`$`(1 .. n)]))) end proc

InnerMatrix := proc (M::Matrix) SubMatrix(M, 2 .. RowDimension(M)-1, 2 .. ColumnDimension(M)-1) end proc

MatrixDet := proc (M::Matrix) local C, n, i, j; n := RowDimension(M)-1; C := Matrix(n, n); seq(seq(assign('C[i, j]', Determinant(M([i, i+1], [j, j+1]))), j = 1 .. n), i = 1 .. n); return C end proc

Dodgson := proc(M::Matrix)
 MatrixDet(M);
InnerMatrix(M) ^~ (-1) *~ MatrixDet(MatrixDet(M));
do if 1 < RowDimension(%) then InnerMatrix(`%%`) ^~ (-1) *~ MatrixDet(%);
end if;
until RowDimension(%) = 1;
Trace(%):
end proc:

Dodgsonseq := proc (E::Matrix) local w, dim, Z; dim := RowDimension(E); Z[dim] := E; Z[dim-1] := MatrixDet(E); Z[dim-2] := `~`[`*`](`~`[`^`](InnerMatrix(E), -1), MatrixDet(MatrixDet(E))); seq(assign('Z[w-1]', `~`[`*`](`~`[`^`](InnerMatrix(Z[w+1]), -1), MatrixDet(Z[w]))), w = dim-1 .. 1, -1); Trace(Z[1]) end proc

LaPlace := proc (M::Matrix) local c; add((-1)^(c+1)*M[1, c]*Minor(M, 1, c), c = 1 .. ColumnDimension(M)) end proc

dim := 7; A := Matrix(dim, dim, shape = symmetric, symbol = a)

7

(1)

start_time := time(); st := time[real](); Det1 := abs(A); CPUtime_used_Build_in_Determinant := time()-start_time; REALtime_used_Build_in_Determinant := time[real]()-st; start_time := time(); st := time[real](); Det2 := DetDef(A); CPUtime_used_Jeremy_Johnson_Determinant := time()-start_time; REALtime_used_Jeremy_Johnson_Determinant := time[real]()-st; start_time := time(); st := time[real](); Det3 := Dodgsonseq(A); CPUtime_usedDodgsonseq := time()-start_time; REALCPUtime_usedDodgsonseq := time[real]()-st; start_time := time(); st := time[real](); Det4 := Dodgson(A); CPUtime_usedDodgson := time()-start_time; REALtime_usedDodgson := time[real]()-st; start_time := time(); st := time[real](); Det5 := LaPlace(A); CPUtime_usedLaPlace := time()-start_time; REALtime_usedLaPlace := time[real]()-st; simplify(Det1-Det2); simplify(Det1-Det3); simplify(Det1-Det4); simplify(Det1-Det5)
``

0.32e-1

 

0.34e-1

 

0.93e-1

 

.108

 

47.094

 

41.295

 

40.766

 

38.158

 

0.31e-1

 

0.50e-1

 

0

 

0

 

0

 

0

(2)

Download test_Determinants_symbolic.mw

For example - I have a for loop acting on a Matrix

a:=Matrix(20,20,rand(0..1.)

for i from 1 to 20 do
  for j from 1 to 20 do
    if a[i,j]<0.2 then a[i,j]:=0 end if:
  end do:
end do:

Is there an equivalent sequence loop?  I tried to set up a double seq to set the values in the matrix but this fails

seq(seq(`if`(a[i,j]<0.2,a[i,j]:=0,a[i,j]),i=1..20),j=1..20)

guys..i need help ...how to find the answer for this equation..for all value of in and b in (a and b)...for all combination of a and b

problem.mw

Hello everybody! 

Since least squares is not fully understood by me all that well, and the way my Dutch book throws me into the deep whitout really showing how things are done, i decided to look for some videos on Least Squares in Maple on YouTube. Well, i did found one, but then this happened. "Error, (in sum) summation variable previously assigned, second argument evaluates to 1 = 1 .. 5" I just want to go further with the video, but now im stuck and i have no clue how to go on. 

https://youtu.be/8zh73UrJW6M?t=948 This is the video at the moment the part where i get stuck is shown. 

I really like these sort of videos while they really do help out. I think its great. 

This is my maple worksheet:


 

with(Statistics); with(CurveFitting); with(LinearAlgebra); with(Optimization); with(plots); interface(imaginaryunit = I)

I

(1)

"f(x):=b[0]+(&sum;)(b[k]*sin(k*x))"

proc (x) options operator, arrow, function_assign; b[0]+sum(b[k]*sin(k*x), k = 1 .. 5) end proc

(2)

X := [seq(3.*k*(1/10), k = 1 .. 10)]

[.3000000000, .6000000000, .9000000000, 1.200000000, 1.500000000, 1.800000000, 2.100000000, 2.400000000, 2.700000000, 3.000000000]

(3)

Y := map(proc (x) options operator, arrow; x^2 end proc, X)

[0.9000000000e-1, .3600000000, .8100000000, 1.440000000, 2.250000000, 3.240000000, 4.410000000, 5.760000000, 7.290000000, 9.000000000]

(4)

F := CurveFitting:-LeastSquares(X, Y, x, curve = f(x))

HFloat(9.017880939782968)-HFloat(7.700034497920161)*sin(x)-HFloat(3.0589327899122045)*sin(2.*x)-HFloat(1.6899646233017431)*sin(3.*x)-HFloat(1.40247653582845)*sin(4.*x)-HFloat(0.82531550630546)*sin(5.*x)

(5)

smartplot(HFloat(9.017880939782968)-HFloat(7.700034497920161)*sin(x)-HFloat(3.0589327899122045)*sin(2.*x)-HFloat(1.6899646233017431)*sin(3.*x)-HFloat(1.40247653582845)*sin(4.*x)-HFloat(0.82531550630546)*sin(5.*x))

 

display(data, plot(f(x), x = 0 .. 3))

Warning, expecting only range variable x in expression b[0]+b[1]*sin(x)+b[2]*sin(2*x)+b[3]*sin(3*x)+b[4]*sin(4*x)+b[5]*sin(5*x) to be plotted but found names [b[0], b[1], b[2], b[3], b[4], b[5]]

 

Error, (in plots:-display) expecting plot structure but received: data

 

data := LinearAlgebra:-Transpose(`<,>`(`<|>`(.3000000000, .6000000000, .9000000000, 1.200000000, 1.500000000, 1.800000000, 2.100000000, 2.400000000, 2.700000000, 3.000000000), `<|>`(0.9000000000e-1, .3600000000, .8100000000, 1.440000000, 2.250000000, 3.240000000, 4.410000000, 5.760000000, 7.290000000, 9.000000000)))

Matrix(%id = 18446746050376108382)

(6)

p1 := plot(data, style = point, color = "green")

 

display(p1, plot(F, x = 0 .. 3), plot(x^2, x = 0 .. 3, color = "black"))

 

with(CurveFitting)

``

CurveFitting[Interactive](X, Y)

9.01788093978297-7.70003449792016*sin(x)-3.0589327899122*sin(2.*x)-1.68996462330174*sin(3.*x)-1.40247653582845*sin(4.*x)-.82531550630546*sin(5.*x)

(7)

smartplot(9.01788093978297-7.70003449792016*sin(x)-3.0589327899122*sin(2.*x)-1.68996462330174*sin(3.*x)-1.40247653582845*sin(4.*x)-.82531550630546*sin(5.*x))

 

with*LinearAlgebra

LinearAlgebra:-LeastSquares({Equate(`~`[f](X), Y)[]}, {seq(b[k], k = 0 .. 5)})

{b[0] = HFloat(9.017880939782952), b[1] = HFloat(-7.700034497920145), b[2] = HFloat(-3.0589327899122054), b[3] = HFloat(-1.6899646233017416), b[4] = HFloat(-1.4024765358284492), b[5] = HFloat(-0.8253155063054547)}

(8)

A, v := LinearAlgebra:-GenerateMatrix(Equate(`~`[f](X), Y), [seq(b[k], k = 0 .. 5)]); LinearAlgebra:-LeastSquares(A, v)

Vector[column](%id = 18446746050376098150)

(9)

Optimization:-LSSolve([v, A])

[2.61443732196701051, Vector[column](%id = 18446746050376094654)]

(10)

Optimization:-LSSolve([seq(f(X[k])-Y[k], k = 1 .. 10)])

Error, (in sum) summation variable previously assigned, second argument evaluates to 1 = 1 .. 5

 

NULL


Thank you very much! 

Greetings,

 

The Function
 

Download Least-Squares_Fitting_in_Maple_video.mw

Why I get "Error, invalid subscript selector" error in my code?

y1 := Grid:-Seq(UP1(s, U, V, W, Phi, Xi, N, a, b, II, JJ, A, B, Dd, M, Ns), s = 1 .. 7);
UKt := add(y1[i], i = 1 .. 7);

Error, invalid subscript selector

As you can see y1 is defined without any problem and have 7 seqments, but the next line warns invalid subscript selector.

Please how can I define two sequences in a procedure with two arguments?

  ans:= Array([seq( [j, doCalc(j, u)], j=-2..0, 0.006, u=1..334)]):

The procedure is doCalc(j,u)  and I received this error: invalid input: seq expects between 1 and 3 arguments, but received 4

Find attached my complete code.Seq_Proc.mw

How do I create a pointplot with different values of a parameter?

I tried

pointplot([seq([k, a(k, a0)], k = 0 .. 10, a0 = [0, 50, 100, 150, 200])]);
Error, invalid input: seq expects its 3rd argument, step, to be of type numeric, but received a0 = [0, 50, 100, 150, 200]
NULL;

So all I'm trying to do is a simple sequence like seq(i^2, i=1..10, 1) but with units.  The seq function is part of the Units:-Standard and Units:-Simple packages.  I couldn't find any examples with units in the help system.  For my first attempt, I tried to create a simple sequence of values with units using what is, to me, a logical syntax.  I have included the Maple input below.  I bolded the input.

with(Units:-Standard);
[*, +, -, /, <, <=, <>, =, Im, Re, ^, abs, add, arccos, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsin, 

  arcsinh, arctan, arctanh, argument, ceil, collect, combine, conjugate, cos, cosh, cot, coth, csc, csch, csgn, diff, eval, 

  evalc, evalr, exp, expand, factor, floor, frac, int, ln, log,  log10, log2, max, min, mul, normal, polar, root, round, sec, 

  sech, seq, shake, signum, simplify, sin, sinh, sqrt, surd, tan,   tanh, trunc, type, verify]

seq(ii, ii = 1.0*Unit('m') .. 10.0*Unit('m'), 1.0*Unit('m'));

Error, (in Units:-Standard:-seq) wrong number (or type) of parameters in function seq

Can anyone show me the correct syntax for this?  Is there something in the help?  I tried it in 2021 and 2022 with the same result.
 

1 2 3 4 5 6 7 Page 1 of 8