MaplePrimes Questions

This question was inspired by https://www.mapleprimes.com/questions/235613-Convert-A-List-With-Nested-Ordered-Sets.

I want to replace several characters of a string separately. 

s:="[ (0, 1), (1, 2), (1, 10), (2, 3), (3, 4), (4, 5), (4, 9), (5, 6), (6, 7), (7, 8),(8, 9), (10, 11), (11, 12), (11, 16), (12, 13), (13, 14), (14, 15), (15, 16)]"

Like this their will be many say n element then I need to a list as 

{{0,1},{1,2},{1,10},......}

I took the for-loop as follows, but I'm wondering if there's a more concise way to deal with it.

with(StringTools):
L:="[ (0, 1), (1, 2), (1, 10), (2, 3), (3, 4), (4, 5), (4, 9), (5, 6), (6, 7), (7, 8),(8, 9), (10, 11), (11, 12), (11, 16), (12, 13), (13, 14), (14, 15), (15, 16)]":    
L1:=["(",")","[","]"]:
L2:=["{","}","{","}"]:
X:=L:
for i from 1 to nops(L1) do
X:=SubstituteAll(X,L1[i],L2[i]);
end do:
parse(X)

{{0, 1}, {1, 2}, {1, 10}, {2, 3}, {3, 4}, {4, 5}, {4, 9}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {10, 11}, {11, 12}, {11, 16}, {12, 13}, {13, 14}, {14, 15}, {15, 16}}

I know that a function acting repeatedly can use f @@ n, for example,

(sin@@2)(x);

But if f  has some  arguments, can it still be used?

I am trying to call an optimization function for a set of operations where the object function contains integrals. i get this error when i try to do the optimization, i actually want to optimize a cost function, this is the error i get: Error, (in Optimization:-NLPSolve) integration range or variable must be specified in the second argument, got 1. = 4 .. 7

here is my work: 

a2 := 18;
b2 := 5;
a1 := 3;
b1 := 2.5;
ci := 0.05;
cr := 1;
cf := 10;
p := 0.1;
L := 0.5;
S := 3;
T := 10;
cud := 50;
co := 0.02;
tr := 0.006;
ti := 0.0014;
tf := 0.014;
K := 2;
A := 2;
M := 7;
f01 := x -> b1*(x/a1)^(b1 - 1)*exp(-(x/a1)^b1)/a1;
f02 := x -> b2*(x/a2)^(b2 - 1)*exp(-(x/a2)^b2)/a2;
fx := x -> p*f01(x) + (1 - p)*f02(x);
fh := h -> L*exp(-L*h);
Fh := h -> 1 - exp(-L*h);

P1_1 := (K, A, M) -> sum(int(fx(x)*(1 - Fh(i*A - x)), x = (i - 1)*A .. i*A), i = 1 .. K);
L1_1 := (K, A, M) -> sum((i*A + tr + i*ti)*P1_1(K, A, M), i = 1 .. K);
C1_1 := (K, A, M) -> sum((ci*i + cr)*P1_1(K, A, M), i = 1 .. K);
NULL;
P2_1 := (K, A, M) -> sum(int(fh(h)*fx(x), [h = 0 .. i*A - x, x = (i - 1)*A .. i*A]), i = 1 .. K);
L2_1 := (K, A, M) -> sum((tf + (i - 1)*ti)*int((x + h)*fh(h)*fx(x), [h = 0 .. i*A - x, x = (i - 1)*A .. i*A]), i = 1 .. K);
C2_1 := (K, A, M) -> sum(((i - 1)*ci + cf)*P2_1(K, A, M), i = 1 .. K);
P3_1 := (K, A, M) -> int(fh(h)*fx(x), [h = 0 .. M - x, x = A*K .. M]);
L3_1 := (K, A, M) -> (K*ti + tf)*int((x + h)*fh(h)*fx(x), [h = 0 .. M - x, x = A*K .. M]);
C3_1 := (K, A, M) -> (K*ci + cf)*P3_1(K, A, M);
P4_1 := (K, A, M) -> int(fx(x)*(1 - Fh(M - x)), x = A*K .. M);
L4_1 := (K, A, M) -> (K*ti + tr + M)*int(fx(x)*(1 - Fh(M - x)), x = A*K .. M);
C4_1 := (K, A, M) -> (K*ci + cr)*int(fx(x)*(1 - Fh(M - x)), x = A*K .. M);
P5_1 := (K, A, M) -> int(fx(x), x = M .. infinity);
L5_1 := (K, A, M) -> (K*ti + tr + M)*int(fx(x), x = M .. infinity);
C5_1 := (K, A, M) -> (K*ci + cr)*int(fx(x), x = M .. infinity);
Ptotal_1 := (K, A, M) -> P1_1(K, A, M) + P2_1(K, A, M) + P3_1(K, A, M) + P4_1(K, A, M) + P5_1(K, A, M);
Ptotal_1(K, A, M);
evalf(Ptotal_1(K, A, M));
Ltotal_1 := (K, A, M) -> L1_1(K, A, M) + L2_1(K, A, M) + L3_1(K, A, M) + L4_1(K, A, M) + L5_1(K, A, M);
evalf(Ltotal_1(K, A, M));
Ctotal_1 := (K, A, M) -> C1_1(K, A, M) + C2_1(K, A, M) + C3_1(K, A, M) + C4_1(K, A, M) + C5_1(K, A, M);
Cost_rate_1 := (K, A, M) -> Ctotal_1(K, A, M)/Ltotal_1(K, A, M);
integralOF := int(Cost_rate_1(K, A, M), x = 1 .. 2);
evalf(integralOF);
                          0.2759938793

MTBOF := Ltotal_1(K, A, M)/(P2_1(K, A, M) + P3_1(K, A, M));
evalf(MTBOF);
                          159.4642167

rd := 1/MTBOF;
ro := 1/M + rd;
const1 := 0 <= K;
const2 := K*A <= M;
const3 := M <= 20;
const4 := 0 <= A;
const5 := 0 <= M;
totalconstr := {const1, const2, const3, const4, const5};

optimized_cost := Optimization:-Minimize(integralOF, totalconstr);
Error, (in Optimization:-NLPSolve) integration range or variable must be specified in the second argument, got 1. = 4 .. 7
NULL;
 

please, i need assitance urgently.. thanks

  In my current worksheet mine.mw how do I automatically print/show the filename " mine.mw"

I have list say like this

[(0, 1), (1, 2), (1, 10), (2, 3), (3, 4), (4, 5), (4, 9), (5, 6), (6, 7), (7, 8), (8, 9), (10, 11), (11, 12), (11, 16), (12, 13), (13, 14), (14, 15), (15, 16)]

 

I want to convert it to

{{0,1},{1,2},{1,10},{2,3},.........}

And print the ouput to a file 

This I want the output as 

 

Graph({{0,1},{1,2},{1,10},{2,3},.........})

 

So that i can save the graph

like that all the order pairs in the above list 

 

I have given one list above here 

But if I have a list of lists like this below

[[(0, 1), (1, 2), (1, 10), (2, 3), (3, 4), (4, 5), (4, 9), (5, 6), (6, 7), (7, 8), (8, 9), (10, 11), (11, 12), (11, 16), (12, 13), (13, 14), (14, 15), (15, 16)], [(0, 10), (1, 2), (1, 9), (2, 3), (3, 4), (4, 5), (4, 9), (5, 6), (6, 7), (7, 8), (8, 9), (10, 11), (11, 12), (11, 16), (12, 13), (13, 14), (14, 15), (15, 16)],.......]

Like this their will be many say n element then I need to a list as 

[{{0,1},{1,2},{1,10},......}, {{0,10},......}, ....]

I ask for a list of graphs as I want the first graph in the first place only , second in the second place only.

Kind help

I would appreciate any help to solve the following Partial Differential Equation, which is a mix of partial and regular derivatives as coefficients.

How to solve it with/without initial conditions?

What is happening at f(0)?

Look at PlotProblem.mw

Dear Users,
I hope you are doing well. The following is the code to solve a nonlinear PD equation numerically and I plotted the graphs for T(y,t) sucessfully.

restart; with(plots); PDE1 := Pr*(diff(T(y, t), t)-Ree*(diff(T(y, t), y))) = (1+Nr*(T(y, t)+1)^3)*(diff(T(y, t), y, y))+3*Nr*(T(y, t)+1)^2*(diff(T(y, t), y))^2; ICandBC := {T(1, t) = 1, T(y, 0) = 1, (D[1](T))(0, t) = T(0, t)}; Ree := .1; Pr := 6.2; HA1 := [0, 1, 10]; AA := [red, green, blue, cyan, purple, black];
printlevel := 2; for i to nops(HA1) do Nr := op(i, HA1); print("Nr = ", %); PDE[i] := {PDE1}; pds[i] := pdsolve(PDE[i], ICandBC, numeric, spacestep = 1/200, timestep = 1/100); PlotsT[i] := pds[i]:-plot[display](T(y, t), t = 1, linestyle = "solid", labels = ["y", "u"], color = op(i, AA), numpoints = 800) end do;
display([`$`(PlotsT[j], j = 1 .. nops(HA1))], size = [1000, 600], axes = boxed, labels = [x, (convert("T", symbol))(x, T)], labelfont = ["Times", 14, Bold], labeldirections = [horizontal, vertical], axesfont = ["Arial", 14, Bold], thickness = 3)

I want to plot the graphs for (1+Nr*(T(y, t)+1)^3)*(diff(T(y, t), y)), at t = 1. Also want to plot diff(T(y, t), y) at y = 0 and y = 1 against Nr. Kindly help me in this matter.

Writing an explanatory paragrah i want to use an approximately equal symbol. How can I do this? The palette has lots of symbols but not what in latex would be done with \approx

I just tried to solve a very simple system of equations using solve but depending on how I write the system the command does out give any output. 

restart

solve({I__cm = m*r^2, r*T = I__cm*a/r, g*m-T = m*a}, {T, a})

solve({r*T = m*r^2*a*(1/r), g*m-T = m*a}, {T, a})

{T = (1/2)*m*g, a = (1/2)*g}

(1)

NULL

Solution with pencil and paper

T := (1/2)*m*g = (1/2)*m*gNULL

a := (1/2)*g = (1/2)*gNULL

Check this solution

evalb(g*m-T = m*a)

true

(2)

evalb(r*T = m*r^2*a*(1/r))

true

(3)

NULL


Notice that if I define I__cm then there is no solution being shown. I can rename I__cm to something else like y, still no output. Then in the second system I simply sub I__cm into the equation that has this variable, and it works.

So what's going on here? Why doesn't the first use of solve work?

Download solveSys.mw

How to read the topological structure of chemical from a SMILES file in Maple 

As I want only the physical structure of the molecule

Like in molecular data it gives the bonds of topology {1,2} like the structure it gives

As SMILES can give 2D structure to me 

Kind help how to do 

My following code:

restart;
PDE := diff(u(x, t), t) + u(x, t)*diff(u(x, t), x) - 0.1*diff(diff(u(x, t), x), x) = 0;
IC := u(x, 0) = sin(x);
BC := [u(0, t) = u(2*Pi, t)];
pds := {BC, IC, PDE};
ds := {pds, t = 0 .. 10, x = 0 .. 2*Pi};
p := pdsolve(ds, numeric);
u := rhs(p[1]);
u(x, t);

producing following 2 errors, don't know how to handle?

Error, (in anonymous procedure called from pdsolve/numeric) invalid terms in sum: 0 .. 10
Error, invalid input: rhs received p[1], which is not valid for its 1st argument, expr

How to make this program more effective ?
 

A := [-3, 1, 2];
B := [-2, -1, 1];
C := [0, 3, -3];
                        A := [-3, 1, 2]

                        B := [-2, -1, 1]

                        C := [0, 3, -3]

alpha[1] := 2;#weight
alpha[2] := -1;
alpha[3] := 1;
                         alpha[1] := 2

                         alpha[2] := -1

                         alpha[3] := 1

x[1] := A[1];
x[2] := B[1];
x[3] := C[1];
                           x[1] := -3

                           x[2] := -2

                           x[3] := 0

y[1] := A[2];
y[2] := B[2];
y[3] := C[2];
                           y[1] := 1

                           y[2] := -1

                           y[3] := 3

z[1] := A[3];
z[2] := B[3];
z[3] := C[3];
                           z[1] := 2

                           z[2] := 1

                           z[3] := -3

sum(alpha[i], i = 1 .. 3);
                               2

xG := sum(alpha[i]*x[i], i = 1 .. 3)/sum(alpha[i], i = 1 .. 3);
                            xG := -2

yG := sum(alpha[i]*y[i], i = 1 .. 3)/sum(alpha[i], i = 1 .. 3);
                            yG := 3

zG := sum(alpha[i]*z[i], i = 1 .. 3)/sum(alpha[i], i = 1 .. 3);
                            zG := 0
Thank you.

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

Is there a way to execute an entire worksheet for a list of values of a parameter.
Sometimes executing in the standard loop can be cumbersome given you have to add catch statements for errors to prevent the loop from stopping.

Hi,

I'm not able to find a way to bring an equation into it's "polynomial" form:

I'd like this expression in the form of:

c1*v^3+c2*v^2+c1*v+c0 = 0

where c1...c4 are my coefficients

How can I do that? 

First 22 23 24 25 26 27 28 Last Page 24 of 2214