acer

32303 Reputation

29 Badges

19 years, 309 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The plot shows that the local maximum is the global maximum over that range t=0..2.

So you can use the Optimization:-Maximize command.

In my opinion this is more straightforward, flexible, and likely more accurate in general than either examining the discrete data points from a plot structure, or using an interpolated spline.

I use the output=listprocedure option for dsolve, as a convenient way to get at procedures for xn(t) and zn(t), similarly to what I showed in your previous Question.

restart

q1 := 3b1 := 20l1 := 22r1 := .5m1 := 900g1 := -11
u0 := -10

v0 := -10x0 := 0z0 := 20xa := 0za := z0+5mu1 := .1omega0 := -24

mn := q1*g1*b1*za

fz := mn/za

TM1 := (2/5)*m1*r1^2

``

"Lp(t):=sqrt((xn(t)-xa)^(2)+(zn(t)-za)^(2)) :"

"Lr(t):=piecewise(sqrt(zn(t)^(2)+A1(t)^(2))>0,sqrt(zn(t)^(2)+A1(t)^(2)),0)  :"

"A1(t):=piecewise((xa-xn(t))>0,xa-xn(t),0):"

"sinalpha1(t):=piecewise((xa-xn(t))>0,(xa-xn(t))/(Lp(t)),0) :"

"cosalpha1(t):=piecewise((xa-xn(t))>0,((za-zn(t)))/(Lp(t)),1) :"

"alpha2(t):=arccos(cosalpha1(t))+phi(t) :"

NULL

"S1(t):=piecewise(zn(t)>=0 and xn(t)<=xa,fz*Lr(t),0):"

"S1z(t):=S1(t)*cos(phi(t)):"

"S1x(t):=S1(t)*sin(-phi(t)):"

"S2(t):=piecewise(xn(t)<=xa and zn(t)>0, (-1) S1(t)*exp(mu1*alpha2(t)),0) :"

"S2x(t):=S2(t)*sinalpha1(t):"

"S2z(t):=S2(t)*cosalpha1(t) :"

"Sx(t):=S2x(t)+S1x(t) :"

"Sz(t):=S1z(t)+S2z(t)+m1*g1:"

shape_factor := 10

"Fr(t):=S2(t)+S1(t)+shape_factor:"

NULL

NULL

"m(t):=Lr(t)q1*b1:"

NULL

"J(t):=1/(3)*m(t)*Lr(t)^(2) :"

"M(t):=g1*m(t)*(Lr(t))/(2)*sin(phi(t)) :"

k := 50*m1

NULL

NULL

``

eqx1 := m1*(diff(u(t), t)) = 0.; eqz1 := m1*(diff(v(t), t)) = m1*g1

900*(diff(u(t), t)) = 0.

900*(diff(v(t), t)) = -9900

eqx0 := diff(x(t), t) = u(t); eqz0 := diff(z(t), t) = v(t)

``

eqx1n := m1*(diff(un(t), t)) = Sx(t); eqz1n := m1*(diff(vn(t), t)) = m1*g1+S1z(t)+S2z(t)

eqx0n := diff(xn(t), t) = un(t); eqz0n := diff(zn(t), t) = vn(t)

eqr1 := TM1*(diff(omega(t), t)) = (S2(t)+S1(t)+shape_factor)*r1

NULL

u0n := u0*m1/(m1+mn)

15/26

NULL

phid0 := 2*u0n(t)/(l1-z0)

15/26

NULL

eqp := (diff(phi(t), t, t))*J(t) = M(t)-k*(diff(phi(t), t))

with(plots)

NULL

NULL

ini := x(0) = x0, u(0) = u0, z(0) = z0, v(0) = v0, xn(0) = x0, un(0) = u0, zn(0) = z0, vn(0) = v0, omega(0) = omega0, phi(0) = 0, (D(phi))(0) = phid0

sol1 := dsolve({eqp, eqr1, eqx0, eqx0n, eqx1, eqx1n, eqz0, eqz0n, eqz1, eqz1n, ini}, {omega(t), phi(t), u(t), un(t), v(t), vn(t), x(t), xn(t), z(t), zn(t)}, type = numeric, output = listprocedure)

odeplot(sol1, [t, 180*arccos(cosalpha1(t))/Pi], 0 .. 2, legend = ["alpha"], linestyle = [dashdot, solid], size = [300, 300])

temp := unapply(subs(xn = Xn, zn = Zn, cosalpha1(t)), t)

proc (t) options operator, arrow; piecewise(0 < -Xn(t), (25-Zn(t))/(Xn(t)^2+(Zn(t)-25)^2)^(1/2), 1) end proc

Xn := eval(xn(t), sol1)

Zn := eval(zn(t), sol1)

plot([t, 180*arccos(temp(t))/Pi, t = 0 .. 2], legend = ["alpha"], linestyle = [dashdot, solid], size = [300, 300])

Optimization:-Maximize(180*arccos(temp(t))/Pi, t = 0 .. 2)

[HFloat(22.00633969122702), [t = HFloat(0.6180259177597804)]]

 

Download evalv_max_ac.mw

There's nothing intrinsically wrong with returning NULL as an explicit statement. This is a common programming technique in Maple.

   return NULL;

One alternative is to have a statement that does nothing and happens to also return NULL, but that would be obfuscation for no benefit. The explicit return call is clear and understandable programming.

ps. Using assign brings the burden of having to remember that happens to return NULL. Since you didn't already think of that then using it would entail one more thing for you to remember. You already know what explicitly returning NULL means, and it's more likely that others reading your code would too.

Without a range supplied fsolve is trying to find roots from A=-infinity to A=infinity. That search is missing values very close to zero.

[edit] The situation is made more difficult due to the root lying close to a singularity, where it is steep, and with the expression nonreal on its other side.

restart:

N := 60: L := 10: a := 2*10^(-12):

eqn:=ns=1-((((N/A)+((A*L)^(L/(1-L))))^((1-L)/L))/(A*L))*(2+(a*exp((((N/A)+((A*L)^(L/(1-L)))))^(1/L)))/((A*L*(((N/A)+((A*L)^(L/(1-L))))^((L-1)/L)))+((a*exp((((N/A)+((A*L)^(L/(1-L)))))^(1/L)))))):

seq(fsolve(eqn,A=0..1e-6),ns=[0.9603,0.9647,0.9691]);

0.9300682773e-9, 0.3054144319e-8, 0.1172662805e-7

Download A_ac.mw

Here are two ways:
1) using plots:-odeplot directly with the sol1 returned by dsolve.
2) using plots:-spacecurve with procedures returned in sol1 by dsolve.

The second way requires some use of eval to extract the various results (after applying procedures at a numeric t value). There are a couple of ways to do that. I show one way that utilizes the output=listprocedure option. It can also be done without that option, using eval slightly differently. The first way looks simpler to me.

restart

q1 := 3

b1 := 20

l1 := 22

r1 := .5

m1 := 900

g1 := -11

u0 := -10

v0 := -10

 

x0 := 0

 

z0 := 20

 

xa := 0

 

za := z0+5

 

mu1 := .1

omega0 := -24

mn := q1*g1*b1*za

fz := mn/za

TM1 := (2/5)*m1*r1^2

3

20

22

.5

900

-11

-10

-10

0

20

0

25

.1

-24

-16500

-660

90.00000000

NULL

"Lp(t):=sqrt((xn(t)-xa)^(2)+(zn(t)-za)^(2)) "

proc (t) options operator, arrow, function_assign; sqrt((xn(t)-xa)^2+(zn(t)-za)^2) end proc

"Lr(t):=piecewise(sqrt(zn(t)^(2)+A1(t)^(2))>0,sqrt(zn(t)^(2)+A1(t)^(2)),0)  "

proc (t) options operator, arrow, function_assign; piecewise(0 < sqrt(zn(t)^2+A1(t)^2), sqrt(zn(t)^2+A1(t)^2), 0) end proc

"A1(t):=piecewise((xa-xn(t))>0,xa-xn(t),0)"

proc (t) options operator, arrow, function_assign; piecewise(0 < xa-xn(t), xa-xn(t), 0) end proc

"sinalpha1(t):=piecewise((xa-xn(t))>0,(xa-xn(t))/(Lp(t)),0) "

proc (t) options operator, arrow, function_assign; piecewise(0 < xa-xn(t), (xa-xn(t))/Lp(t), 0) end proc

"cosalpha1(t):=piecewise((xa-xn(t))>0,((za-zn(t)))/(Lp(t)),1) "

proc (t) options operator, arrow, function_assign; piecewise(0 < xa-xn(t), (za-zn(t))/Lp(t), 1) end proc

"alpha2(t):=arccos(cosalpha1(t))+phi(t) "

proc (t) options operator, arrow, function_assign; arccos(cosalpha1(t))+phi(t) end proc

NULL

"S1(t):=piecewise(zn(t)>=0 and xn(t)<=xa,fz*Lr(t),0)"

proc (t) options operator, arrow, function_assign; piecewise(0 <= zn(t) and xn(t) <= xa, fz*Lr(t), 0) end proc

"S1z(t):=S1(t)*cos(phi(t))"

proc (t) options operator, arrow, function_assign; S1(t)*cos(phi(t)) end proc

"S1x(t):=S1(t)*sin(-phi(t))"

proc (t) options operator, arrow, function_assign; S1(t)*sin(-phi(t)) end proc

"S2(t):=piecewise(xn(t)<=xa and zn(t)>0, (-1) S1(t)*exp(mu1*alpha2(t)),0) "

proc (t) options operator, arrow, function_assign; piecewise(xn(t) <= xa and 0 < zn(t), -S1(t)*exp(mu1*alpha2(t)), 0) end proc

"S2x(t):=S2(t)*sinalpha1(t)"

proc (t) options operator, arrow, function_assign; S2(t)*sinalpha1(t) end proc

"S2z(t):=S2(t)*cosalpha1(t) "

proc (t) options operator, arrow, function_assign; S2(t)*cosalpha1(t) end proc

"Sx(t):=S2x(t)+S1x(t) "

proc (t) options operator, arrow, function_assign; S2x(t)+S1x(t) end proc

"Sz(t):=S1z(t)+S2z(t)+m1*g1"

proc (t) options operator, arrow, function_assign; S1z(t)+S2z(t)+m1*g1 end proc

shape_factor := 10

10

"Fr(t):=S2(t)+S1(t)+shape_factor"

proc (t) options operator, arrow, function_assign; S2(t)+S1(t)+shape_factor end proc

NULL

``

"m(t):=Lr(t)q1*b1"

proc (t) options operator, arrow, function_assign; Lr(t)*q1*b1 end proc

``

"J(t):=1/(3)*m(t)*Lr(t)^(2) "

proc (t) options operator, arrow, function_assign; (1/3)*m(t)*Lr(t)^2 end proc

"M(t):=g1*m(t)*(Lr(t))/(2)*sin(phi(t)) "

proc (t) options operator, arrow, function_assign; (1/2)*g1*m(t)*Lr(t)*sin(phi(t)) end proc

k := 50*m1

45000

NULL

NULL

NULL

eqx1 := m1*(diff(u(t), t)) = 0.; eqz1 := m1*(diff(v(t), t)) = m1*g1

900*(diff(u(t), t)) = 0.

900*(diff(v(t), t)) = -9900

eqx0 := diff(x(t), t) = u(t); eqz0 := diff(z(t), t) = v(t)

diff(x(t), t) = u(t)

diff(z(t), t) = v(t)

NULL

eqx1n := m1*(diff(un(t), t)) = Sx(t); eqz1n := m1*(diff(vn(t), t)) = m1*g1+S1z(t)+S2z(t)

eqx0n := diff(xn(t), t) = un(t); eqz0n := diff(zn(t), t) = vn(t)

diff(xn(t), t) = un(t)

diff(zn(t), t) = vn(t)

eqr1 := TM1*(diff(omega(t), t)) = (S2(t)+S1(t)+shape_factor)*r1

NULL

u0n := u0*m1/(m1+mn)

15/26

``

phid0 := 2*u0n(t)/(l1-z0)

15/26

``

eqp := (diff(phi(t), t, t))*J(t) = M(t)-k*(diff(phi(t), t))

with(plots)

``

NULL

ini := x(0) = x0, u(0) = u0, z(0) = z0, v(0) = v0, xn(0) = x0, un(0) = u0, zn(0) = z0, vn(0) = v0, omega(0) = omega0, phi(0) = 0, (D(phi))(0) = phid0

x(0) = 0, u(0) = -10, z(0) = 20, v(0) = -10, xn(0) = 0, un(0) = -10, zn(0) = 20, vn(0) = -10, omega(0) = -24, phi(0) = 0, (D(phi))(0) = 15/26

sol1 := dsolve({eqp, eqr1, eqx0, eqx0n, eqx1, eqx1n, eqz0, eqz0n, eqz1, eqz1n, ini}, {omega(t), phi(t), u(t), un(t), v(t), vn(t), x(t), xn(t), z(t), zn(t)}, type = numeric, output = listprocedure)

odeplot(sol1, [xn(t), t, zn(t)], t = 0 .. 1, thickness = 3, color = red)

Xn := eval(xn(t), sol1); Zn := eval(zn(t), sol1)

spacecurve([Xn(t), t, Zn(t)], t = 0 .. 1, thickness = 3, color = red)

Download unable_to_evaluate_ac.mw

@Syed Asadullah Shah

Your code doesn't initialize F (or T) as an Array, so your assignments to indexed references cause a table to be assigned to F (and T). But your code also shows F(k+2) , which is nonsense. What do you intend by that?

Your attempted second call to pade (inside the solve call) is messed up 2D Input, and is actually being parsed as pade*(...) . You could get rid of that multiplication.

The n that appears in the expressions returned by your procedure gnrpoly is the local variable n of that same procedure.

That escaped local name n is not the same as the global name n, which you are trying to use for substitution at the top-level. That is why your calls to eval are not making a substitution.

There are several ways to fix your issue.

One approach is to utilize unapply (w.r.t that local name n) inside gnrpoly, and have gnrpoly return a procedure. Another way is to pass in the variable name (eg. n, from the higher level) as another parameter of gnrpoly. Below I show the former approach, with unapply.

restart

interface(rtablesize = 12)

[10, 10]

i) Recurrence relation

 

"Recurrence Relation for next column. . The matrix starts at 1,1 not 0,0 A(i,j)=A(i-1,j-1)*(j-2)+A(i,j-1)"
NULL

``NULL

Msize := 12

A := Matrix(Msize)

A[1, 1] := 1

1

for i from 2 to Msize do for j from i to Msize do A[i, j] := A[i, j-1]*(j-2)+A[i-1, j-1] end do end do

A

Matrix(%id = 36893628682748306964)

NULL

NULL

viia)  General formula for diagonals:-

Select diagonal  & Difference Table procedures

 

diag := proc (M::Matrix, dg::posint) local i, rd, c, dt; rd := LinearAlgebra:-RowDimension(M); dt := Matrix(rd, rd); for i from dg to rd do dt[1+i-dg, 1] := M[1+i-dg, i] end do; return dt end proc

diag(A, 5)

Matrix(%id = 36893628682748321172)

diftab := proc (M::Matrix) local i, j, cl, rd; rd := LinearAlgebra:-RowDimension(M); for i from rd by -1 to 1 do if M[i, 1] = 0 then rd := rd-1 else break end if end do; cl := rd; for i from 2 to cl do for j to rd-i do M[j, i] := M[j+1, i-1]-M[j, i-1] end do end do; print(M); return M end proc

diftab(diag(A, 4))

Matrix(%id = 36893628682599410612)

gnrpoly := proc (M::Matrix) local i, p, rd, n; rd := LinearAlgebra:-RowDimension(M); for i from rd by -1 to 1 do if M[1, i] = 0 then rd := rd-1 else break end if end do; p := 0; for i from 0 to rd-1 do p := p+M[1, i+1]*binomial(n, i) end do; return unapply(p, n) end proc

"for i from 0 to 3 do print("Diagonal  ",i);   eqn:=gnrpoly(diftab(diag(A,i+1)));    cat(poly,i):=unapply(factor(expand(eqn(n))),n);    print("--------------------------------------------------------------");  end do"

"--------------------------------------------------------------"

NULL

NULL

NULL

The equations do not evaluate. They are acting inert

poly1(n)

(1/2)*n*(1+n)

poly1(2)

3

poly2(n)

(1/24)*n*(3*n+5)*(n+2)*(1+n)

poly2(3)

35

poly3(n)

(1/48)*n*(1+n)*(n+3)^2*(n+2)^2

poly3(-1)

0

eval(eqn)

proc (n) options operator, arrow; 6*n+38*binomial(n, 2)+93*binomial(n, 3)+111*binomial(n, 4)+65*binomial(n, 5)+15*binomial(n, 6) end proc

eqn(4)

735

``

Download Q_10-10-22_gentrate_eqn_ac.mw

ps. You used the term "inert". This is not an issue of inertness.

I disagree with your claim that "foo() has z" used.

The only z that foo "has" (apart from its declaration as a local of foo) is as a parameter of an anonymous procedure defined and used within foo. And that is not the same z as the local z of foo.

The local z of foo is not used within foo.

An alternative is,

  plots:-textplot([2,2,InertForm:-Display(%floor(5.5),'inert'=false)])

You could use the inert form %log[b] . You might also use InertForm:-Display(..,inert=false) to get that rendered in black (instead of gray).

DisplayLogQCM_ac.mw

How about specifiying the types on the (procedural) parameters in the preliminary call to codegen[makeproc]?

Eg, (notice the parameter specifications of the procedure),

   codegen[makeproc](TheList, parameters = map(`::`, [proc_params], float[8]))

Those were specified programmatically, not manually.

List of optimized equations

old_eq := [t11 = cos(R4_theta(t)), t12 = cos(R3_theta(t)), t9 = sin(R4_theta(t)), R1_theta(t) = -arctan(t9*t12/t11), t24 = cos(R1_theta(t)), t18 = sin(R1_theta(t)), t56 = t9*t18, t28 = (-t11*t24+t12*t56+1)*ra, t55 = t9*t24, t68 = (t11*t18+t12*t55)*rb, t70 = t28+t68, t69 = t68-t28, t25 = sqrt(2), t52 = t11*t12, t39 = t25*t52, t49 = t24*t25, t67 = (t18*t39+t49*t9)*ra, t10 = sin(R3_theta(t)), t5 = rb*t10*t49, t50 = t18*t25, t59 = (-t24*t39+t50*t9)*rb, t41 = t5+t59, t53 = t10*t11, t54 = 1+200*la, AF_s(t) = -(1/400)*(-400*za*t53+(400*(-s(t)-xa))*t12+((-200*rb+t54)*t12+(200*rb+t54)*t53)*t25)*t25/(t12+t53), t31 = -2*la-2*AF_s(t)+t41, t35 = -2*rb-t5+t59, t7 = ra*t10*t50, t42 = t7+t67, t43 = -t7+t67, A1_R1_theta(t) = arctan((t35+t42)/(t31+t43)), t21 = cos(A1_R1_theta(t)), t44 = la+AF_s(t), t65 = t44*t21, t15 = sin(A1_R1_theta(t)), t62 = (1/2)*t15, t37 = (1/2)*t21+t62, t64 = (t62-(1/2)*t21)*t10+t37*t52, t46 = t15+t21, t63 = (t15-t21)*t10+t46*t52, A3_R1_theta(t) = arctan((-t35+t42)/(-t31+t43)), t23 = cos(A3_R1_theta(t)), t61 = -(1/2)*t23, t58 = t15*rb, t17 = sin(A3_R1_theta(t)), t57 = t17*rb, ASF_R1_theta(t) = arctan(rb*(-2+(t56+(-t10-t52)*t24)*t25)/(t41-t44)), t13 = sin(ASF_R1_theta(t)), t19 = cos(ASF_R1_theta(t)), t48 = t13+t19, t45 = t17+t23, t36 = t61-(1/2)*t17, t34 = t46*t9, t33 = t44*t23, t32 = t37*t9, t27 = t45*t52+(t17-t23)*t10, t26 = -t36*t52+((1/2)*t17+t61)*t10, A3_R2_theta(t) = arctan(2*t70/(2*t57+2*t33+((t24*t27-t45*t56)*rb+(t18*t27+t45*t55)*ra)*t25)), A3_s(t) = -la+t70*sin(A3_R2_theta(t))+(t57+t33+((t24*t26+t36*t56)*rb+(t18*t26-t36*t55)*ra)*t25)*cos(A3_R2_theta(t)), A1_R2_theta(t) = arctan(2*t69/(-2*t58-2*t65+((t18*t34-t24*t63)*rb+(t18*t63+t24*t34)*ra)*t25)), A1_s(t) = -la-t69*sin(A1_R2_theta(t))+(t58+t65+((-t18*t32+t24*t64)*rb+(-t18*t64-t24*t32)*ra)*t25)*cos(A1_R2_theta(t)), ASF_s(t) = -la+t44*t19+(2*t13+(-t48*t56+(t48*t52+(t13-t19)*t10)*t24)*t25)*rb]

Replace functions of t in by names

vars_without_t := {seq(i = op(0, i), `in`(i, indets(old_eq, function(identical(t)))))}

{A1_s(t) = A1_s, A3_s(t) = A3_s, AF_s(t) = AF_s, ASF_s(t) = ASF_s, s(t) = s, A1_R1_theta(t) = A1_R1_theta, A1_R2_theta(t) = A1_R2_theta, A3_R1_theta(t) = A3_R1_theta, A3_R2_theta(t) = A3_R2_theta, ASF_R1_theta(t) = ASF_R1_theta, R1_theta(t) = R1_theta, R3_theta(t) = R3_theta, R4_theta(t) = R4_theta}

TheList := subs(vars_without_t, old_eq)

C code generation

These are the inputs

inputs := s, R4_theta, R3_theta

s, R4_theta, R3_theta

These are the outputs

outputs := A1_s, A3_s, AF_s, ASF_s

A1_s, A3_s, AF_s, ASF_s

Set parameters for Maple procedure

proc_params := la, ra, rb, xa, za, inputs, outputs

la, ra, rb, xa, za, s, R4_theta, R3_theta, A1_s, A3_s, AF_s, ASF_s

Generate a Maple procedure form an optimzied equation list

ik := codegen[makeproc](TheList, parameters = map(`::`, [proc_params], float[8]))

proc (la::(float[8]), ra::(float[8]), rb::(float[8]), xa::(float[8]), za::(float[8]), s::(float[8]), R4_theta::(float[8]), R3_theta::(float[8]), A1_s::(float[8]), A3_s::(float[8]), AF_s::(float[8]), ASF_s::(float[8])) local t10, t11, t12, t13, t15, t17, t18, t19, t21, t23, t24, t25, t26, t27, t28, t31, t32, t33, t34, t35, t36, t37, t39, t41, t42, t43, t44, t45, t46, t48, t49, t5, t50, t52, t53, t54, t55, t56, t57, t58, t59, t61, t62, t63, t64, t65, t67, t68, t69, t7, t70, t9, A1_R1_theta, A1_R2_theta, A3_R1_theta, A3_R2_theta, ASF_R1_theta, R1_theta; t11 := cos(R4_theta); t12 := cos(R3_theta); t9 := sin(R4_theta); R1_theta := -arctan(t9*t12/t11); t24 := cos(R1_theta); t18 := sin(R1_theta); t56 := t9*t18; t28 := (-t11*t24+t12*t56+1)*ra; t55 := t9*t24; t68 := (t11*t18+t12*t55)*rb; t70 := t28+t68; t69 := t68-t28; t25 := 2^(1/2); t52 := t12*t11; t39 := t25*t52; t49 := t24*t25; t67 := (t18*t39+t49*t9)*ra; t10 := sin(R3_theta); t5 := rb*t10*t49; t50 := t18*t25; t59 := (-t24*t39+t50*t9)*rb; t41 := t5+t59; t53 := t11*t10; t54 := 1+200*la; AF_s := -(1/400)*(-400*za*t53+400*(-s-xa)*t12+((-200*rb+t54)*t12+(200*rb+t54)*t53)*t25)*t25/(t12+t53); t31 := -2*la-2*AF_s+t41; t35 := -2*rb-t5+t59; t7 := ra*t10*t50; t42 := t7+t67; t43 := -t7+t67; A1_R1_theta := arctan((t35+t42)/(t31+t43)); t21 := cos(A1_R1_theta); t44 := la+AF_s; t65 := t44*t21; t15 := sin(A1_R1_theta); t62 := (1/2)*t15; t37 := (1/2)*t21+t62; t64 := (t62-(1/2)*t21)*t10+t37*t52; t46 := t15+t21; t63 := (t15-t21)*t10+t46*t52; A3_R1_theta := arctan((-t35+t42)/(-t31+t43)); t23 := cos(A3_R1_theta); t61 := -(1/2)*t23; t58 := t15*rb; t17 := sin(A3_R1_theta); t57 := t17*rb; ASF_R1_theta := arctan(rb*(-2+(t56+(-t10-t52)*t24)*t25)/(t41-t44)); t13 := sin(ASF_R1_theta); t19 := cos(ASF_R1_theta); t48 := t13+t19; t45 := t17+t23; t36 := t61-(1/2)*t17; t34 := t46*t9; t33 := t44*t23; t32 := t37*t9; t27 := t45*t52+(t17-t23)*t10; t26 := -t36*t52+((1/2)*t17+t61)*t10; A3_R2_theta := arctan(2*t70/(2*t57+2*t33+((t24*t27-t45*t56)*rb+(t18*t27+t45*t55)*ra)*t25)); A3_s := -la+t70*sin(A3_R2_theta)+(t57+t33+((t24*t26+t36*t56)*rb+(t18*t26-t36*t55)*ra)*t25)*cos(A3_R2_theta); A1_R2_theta := arctan(2*t69/(-2*t58-2*t65+((t18*t34-t24*t63)*rb+(t18*t63+t24*t34)*ra)*t25)); A1_s := -la-t69*sin(A1_R2_theta)+(t58+t65+((-t18*t32+t24*t64)*rb+(-t18*t64-t24*t32)*ra)*t25)*cos(A1_R2_theta); ASF_s := -la+t44*t19+(2*t13+(-t48*t56+(t48*t52+(t13-t19)*t10)*t24)*t25)*rb end proc

Codegeneration and customization for External C/Library Block App

CodeGeneration[C](ik, defaulttype = double)

#include <math.h>

double ik (
  double la,
  double ra,
  double rb,
  double xa,
  double za,
  double s,
  double R4_theta,
  double R3_theta,
  double A1_s,
  double A3_s,
  double AF_s,
  double ASF_s)
{
  double t10;
  double t11;
  double t12;
  double t13;
  double t15;
  double t17;
  double t18;
  double t19;
  double t21;
  double t23;
  double t24;
  double t25;
  double t26;
  double t27;
  double t28;
  double t31;
  double t32;
  double t33;
  double t34;
  double t35;
  double t36;
  double t37;
  double t39;
  double t41;
  double t42;
  double t43;
  double t44;
  double t45;
  double t46;
  double t48;
  double t49;
  double t5;
  double t50;
  double t52;
  double t53;
  double t54;
  double t55;
  double t56;
  double t57;
  double t58;
  double t59;
  double t61;
  double t62;
  double t63;
  double t64;
  double t65;
  double t67;
  double t68;
  double t69;
  double t7;
  double t70;
  double t9;
  double A1_R1_theta;
  double A1_R2_theta;
  double A3_R1_theta;
  double A3_R2_theta;
  double ASF_R1_theta;
  double R1_theta;
  t11 = cos(R4_theta);
  t12 = cos(R3_theta);
  t9 = sin(R4_theta);
  R1_theta = -atan(t9 * t12 / t11);
  t24 = cos(R1_theta);
  t18 = sin(R1_theta);
  t56 = t9 * t18;
  t28 = (-t11 * t24 + t12 * t56 + 0.1e1) * ra;
  t55 = t9 * t24;
  t68 = (t11 * t18 + t12 * t55) * rb;
  t70 = t28 + t68;
  t69 = t68 - t28;
  t25 = sqrt(0.2e1);
  t52 = t12 * t11;
  t39 = t25 * t52;
  t49 = t24 * t25;
  t67 = (t18 * t39 + t49 * t9) * ra;
  t10 = sin(R3_theta);
  t5 = rb * t10 * t49;
  t50 = t18 * t25;
  t59 = (-t24 * t39 + t50 * t9) * rb;
  t41 = t5 + t59;
  t53 = t11 * t10;
  t54 = 0.1e1 + 0.200e3 * la;
  AF_s = -(-0.400e3 * za * t53 + 0.400e3 * (-s - xa) * t12 + ((-0.200e3 * rb + t54) * t12 + (0.200e3 * rb + t54) * t53) * t25) * t25 / (t12 + t53) / 0.400e3;
  t31 = -0.2e1 * la - 0.2e1 * AF_s + t41;
  t35 = -0.2e1 * rb - t5 + t59;
  t7 = ra * t10 * t50;
  t42 = t7 + t67;
  t43 = -t7 + t67;
  A1_R1_theta = atan((t35 + t42) / (t31 + t43));
  t21 = cos(A1_R1_theta);
  t44 = la + AF_s;
  t65 = t44 * t21;
  t15 = sin(A1_R1_theta);
  t62 = t15 / 0.2e1;
  t37 = t21 / 0.2e1 + t62;
  t64 = (t62 - t21 / 0.2e1) * t10 + t37 * t52;
  t46 = t15 + t21;
  t63 = (t15 - t21) * t10 + t46 * t52;
  A3_R1_theta = atan((-t35 + t42) / (-t31 + t43));
  t23 = cos(A3_R1_theta);
  t61 = -t23 / 0.2e1;
  t58 = t15 * rb;
  t17 = sin(A3_R1_theta);
  t57 = t17 * rb;
  ASF_R1_theta = atan(rb * (-0.2e1 + (t56 + (-t10 - t52) * t24) * t25) / (t41 - t44));
  t13 = sin(ASF_R1_theta);
  t19 = cos(ASF_R1_theta);
  t48 = t13 + t19;
  t45 = t17 + t23;
  t36 = t61 - t17 / 0.2e1;
  t34 = t46 * t9;
  t33 = t44 * t23;
  t32 = t37 * t9;
  t27 = t45 * t52 + (t17 - t23) * t10;
  t26 = -t36 * t52 + (t17 / 0.2e1 + t61) * t10;
  A3_R2_theta = atan(0.2e1 * t70 / (0.2e1 * t57 + 0.2e1 * t33 + ((t24 * t27 - t45 * t56) * rb + (t18 * t27 + t45 * t55) * ra) * t25));
  A3_s = -la + t70 * sin(A3_R2_theta) + (t57 + t33 + ((t24 * t26 + t36 * t56) * rb + (t18 * t26 - t36 * t55) * ra) * t25) * cos(A3_R2_theta);
  A1_R2_theta = atan(0.2e1 * t69 / (-0.2e1 * t58 - 0.2e1 * t65 + ((t18 * t34 - t24 * t63) * rb + (t18 * t63 + t24 * t34) * ra) * t25));
  A1_s = -la - t69 * sin(A1_R2_theta) + (t58 + t65 + ((-t18 * t32 + t24 * t64) * rb + (-t18 * t64 - t24 * t32) * ra) * t25) * cos(A1_R2_theta);
  ASF_s = -la + t44 * t19 + (0.2e1 * t13 + (-t48 * t56 + (t48 * t52 + (t13 - t19) * t10) * t24) * t25) * rb;
  return(ASF_s);
}

NULL

Download C_code_generation_with_CodeGeneration_ac.mw

Your current problem is due to the fact that your collatz procedure is returning NULL.

That is, calls like collatz(13) have a return value of NULL. That happens because the last line of your collatz procedure merely prints max_i. The print command itself returns NULL.

Try it with the very last line of collatz being,

   return max_i;

after (or instead of),

   print(max_i);

Here's one simple way,

   m:=Matrix([[1,2,5,6,9],[3,4,5,13,14],[1,3,4,10,11]]):
   dataplot(m^%T, style=line, gridlines=true, size=[500,"golden"]);

 

The size option is optional. (That instance of "golden" refers to the aspect ratio; I could have used approximately 0.618 instead.)

One way to accomplish that is to set the default unit(s) for which units of that same compound dimension will combine/simplify.

By default Maple's Units environments combine units to the SI standard. The SI standard unit for volume is m^3.

Maple's Units:-UseUnit command allows you to override the SI system, on a dimension-by-dimension basis.

For example,

restart

with(Units:-Simple)

Units:-UseUnit(mol/L)

c = 0.33e-1*Unit('g')/((166.0028*Unit('g'/'mol'))*(0.5e-1*Unit('l')))

c = 0.3975836552e-2*Units:-Unit(mol/L)

Download UseUnit_ex.mw

Note that the above should only affect that particular dimension, eg. amount/volume. That can be distinct from the reciprocal of that dimension, of the square of it, or something with units of mol/m^4, etc.

In some scenarios you may need to call simplify ( or combine(...,units) ) in order to get the units in play to be merged. That can sometimes be true even without this custom use of UseUnit.

I used Maple 2022.1 for the computation above. If you have an earlier version that behaves differently then please tag your Question appropriately.

You can also programmatically convert units to compatible alternatives. That affects a particular result (though further computation with that might result in combining back to the SI standard). This doesn't require UseUnit. For example,

restart

with(Units:-Simple)

expr := c = 0.33e-1*Unit('g')/((166.0028*Unit('g'/'mol'))*(0.5e-1*Unit('l')))

c = 3.975836552*Units:-Unit(mol/m^3)

lhs(expr) = convert(rhs(expr), units, mol/L)

c = 0.3975836552e-2*Units:-Unit(mol/L)

c = convert(0.33e-1*Unit('g')/((166.0028*Unit('g'/'mol'))*(0.5e-1*Unit('l'))), units, mol/L)

c = 0.3975836552e-2*Units:-Unit(mol/L)

Download conv_unit_ex.mw

Yet another alternative (for the RHS of the above only, I suspect, and not that whole equation) is to use the relevant right-click context-menu item to change the display unit for a particular output.

Inside a procedure you can utilize the uses facility.

That allows the procedure to access the package exports without the need to have the package loaded at the higher level. (This can also be useful if you wish to store the procedure within a .mla Library archive, so that it can be subsequently used without the need to load the package. Ie, it can run stand-alone.)

As a toy example,

p := proc(eqs::{list,seq}(`=`), L::list(name))
  local A,B;
  uses LinearAlgebra, ScientificConstants;
  A,B := GenerateMatrix(eqs,L);
  LinearSolve(A,B);
end proc:

p([x+y=4, x-y=2], [x,y]);

Vector(2, {(1) = 3, (2) = 1})

solve([x+y=4, x-y=2], [x,y]);

[[x = 3, y = 1]]

Download uses_example.mw

Some people prefer an alternative, in which the uses facility is utilized to provide a terser way to access the exports, like an abbreviation. This still allows more compact coding, but adds some legibility so that you can more easily recognize what's happening later on.

p := proc(eqs::{list,seq}(`=`), L::list(name))
  local A,B;
  uses LA=LinearAlgebra;
  A,B := LA:-GenerateMatrix(eqs,L);
  LA:-LinearSolve(A,B);
end proc:

p([x+y=4, x-y=2], [x,y]);

Vector(2, {(1) = 3, (2) = 1})

Download uses_example2.mw

Imagine a scenaro like, say,
   uses Cal=Student:-Calculus1;
so that you could have code with calls like Cal:-Roots(...) which is still reasonably terse but also understandable.

In your first example, that use of Physics:-diff causes an assignment to a remember table for top-level :-diff, which can be removed using forget.

restart;

kernelopts(version);

`Maple 2022.1, X86 64 LINUX, May 26 2022, Build ID 1619613`

diff(conjugate(f(x)), x);

(diff(f(x), x))*(-conjugate(f(x))/f(x)+2*abs(1, f(x))/signum(f(x)))

Physics:-diff(conjugate(f(x)), x);

diff(conjugate(f(x)), x)

forget(diff);

diff(conjugate(f(x)), x);

(diff(f(x), x))*(-conjugate(f(x))/f(x)+2*abs(1, f(x))/signum(f(x)))

Download diff_forget.mw

(This can also be seen by examing op(4,...) of the :-diff procedure after that Physics:-diff call is made.

The second example seems more involved, and I haven't yet figured it out. It may be related to the Physics package calls within the Library routine `simpl/conjugate`.

First 60 61 62 63 64 65 66 Last Page 62 of 336