WD0HHU

50 Reputation

4 Badges

4 years, 314 days

MaplePrimes Activity


These are replies submitted by WD0HHU

Dear @acer, I went back and took a hard look at the "subsindents" Help page and I know finally have started to understand what that Maple command is supposed to do! You should have them include your simple but illustrative example to show how powerful this command is!!  Also, I am starting to understand the "evalindets" is about.

Thank you! 

Hello @acer! I took your suggestion and applied the "simplify" command as follows:

simplify(subs(convert(sols[25], list), lhs(sys[7]))) 

and I got the expected "0" result!!

Thank you again.  I always learn things from your responses, probably more than you know!!

Hello @acer again! I was looking at the solutions that came from "sols" and I did the following:  

subs(convert(sols[25], list), lhs(sys[7]))

to substitute a solution -- in this case sols[25], into the sys[7] -- and see if it equaled zero.

I noticed in this case it was non-zero.  It seems like it forgot but it should have included b__1=0 as part of the solution in sols[25].  Am I missing something here?  

Thank you.

Dear @acer, I know your are one of the many Maple "Dads" that know everything! I am sorry but I am baffled by what you did in the 

sols := subsindets([solve(sys,explicit,allsolutions)],`=`,eq->ifelse(eq,NULL,eq));

line of Maple code.  I am especially intrigued by the subsindets command? Is this a standard way to solve this type of system of linear equations with Maple?

Thank you.


 

restart

target := r -> exp(sin(r))

proc (r) options operator, arrow; exp(sin(r)) end proc

(1)

X := < [seq(0..2.0*Pi, Pi/100.0)] >:
Y := (exp@sin)~(X):

model  := r -> a*sin(b*r+c) + d;
Y__est := model~(X):

fit := unapply(Statistics:-NonlinearFit(model(r), X, Y, r), r)

proc (r) options operator, arrow; a*sin(b*r+c)+d end proc

 

proc (r) options operator, arrow; HFloat(1.1349036230282985)*sin(HFloat(1.0079063136739561)*r-HFloat(0.025858569285319585))+HFloat(1.264756992961412) end proc

(2)

plot(
  [exp(sin(r)), fit(r)]
  , r=0..2*Pi
  , color=[blue, red]
  , legend=[typeset(target(r)), typeset(evalf[4](fit(r)))]
  , title = typeset(RMSE = (2*Pi/numelems(X)) * evalf[4](add((fit-target)~(X)^~2)))
)

 

H1 := expand((target-model)(r)^2)

(exp(sin(r)))^2-2*exp(sin(r))*a*sin(b*r)*cos(c)-2*exp(sin(r))*a*cos(b*r)*sin(c)-2*exp(sin(r))*d+a^2*sin(b*r)^2*cos(c)^2+2*a^2*sin(b*r)*cos(c)*cos(b*r)*sin(c)+2*a*sin(b*r)*cos(c)*d+a^2*cos(b*r)^2*sin(c)^2+2*a*cos(b*r)*sin(c)*d+d^2

(3)


Great simplification: given the fit we got above we use the assumption  b = 1

H2 := simplify(eval(H1, b=1));

(a*cos(c)*sin(r)+a*cos(r)*sin(c)+d-exp(sin(r)))^2

(4)

H3 := map(int, H2, r=0..2*Pi)

(int(a*cos(c)*sin(r)+a*cos(r)*sin(c)+d-exp(sin(r)), r = 0 .. 2*Pi))^(4*Pi)

(5)

uH3, kH3 := selectremove(has, [op(H3)], int);

[int(a*cos(c)*sin(r)+a*cos(r)*sin(c)+d-exp(sin(r)), r = 0 .. 2*Pi)], [4*Pi]

(6)

uH4 := IntegrationTools:-Expand(uH3[1])

2*d*Pi-2*Pi*BesselI(0, 1)

(7)

uH5 := evalf(uH4)

6.283185308*d-7.954926524

(8)

M1 := eval(add([uH5, kH3[]]), b=1)

6.283185308*d+4.611444096

(9)

dM1 := diff~(dM1, [a, c, d]);
Sol := solve(%, [a, c, d]);

 print~(Sol):
print~([ seq( [evalf(eval(M1, sol)), sol], sol in Sol) ]):

[0, 0, 0]

 

[[a = a, c = c, d = d]]

 

[a = a, c = c, d = d]

 

[6.283185308*d+4.611444096, [a = a, c = c, d = d]]

(10)

dM2 := Matrix(3, 3, (i, j) -> diff(M1, [a, c, d][i], [a, c, d][j]));

dM2red := dM2[1..2, 1..2];

for sol in Sol do
  eig := LinearAlgebra:-Eigenvalues(eval(dM2red, sol)):
  if evalf(mul(eig)) < 0 then
    printf("\n%a is a saddle point\n", sol)
  elif evalf(eig[1]) > 0 then
    printf("\n%a is a minimum\n", sol)
  else
    printf("\n%a is a maximum\n", sol)  
  end if:
end do:

Matrix(3, 3, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0})

 

Matrix(%id = 36893490502983952972)

 


[a = a, c = c, d = d] is a maximum

 

use plots in
  display(
    plot3d(evalf(eval(M1, Sol[1][3])), a=-1.5..1.5, c=-1..4, style=wireframe, color="LightBlue", lightmodel=light3)
    ,
    pointplot3d(eval([a, c, M1], Sol[2]), symbol=solidcircle, symbolsize=40, color=red)
    ,
    pointplot3d(eval([a, c, M1], Sol[3]), symbol=solidcircle, symbolsize=40, color=red)
    ,
    pointplot3d(eval([a, c, M1], Sol[1]), symbol=solidcircle, symbolsize=40, color=green)
  )
end use;

use plots in
  display(
    contourplot(evalf(eval(M1, Sol[1][3])), a=-1.5..1.5, c=-1..4, color="LightBlue", contours=20)
    ,
    pointplot(eval([a, c], Sol[2]), symbol=solidcircle, symbolsize=20, color=red)
    ,
    pointplot(eval([a, c], Sol[3]), symbol=solidcircle, symbolsize=20, color=red)
    ,
    pointplot(eval([a, c], Sol[1]), symbol=solidcircle, symbolsize=20, color=green)
  )
end use;

Warning, expecting only range variables [a, c] in expression 6.283185308*d+4.611444096 to be plotted but found name d

 

Error, invalid subscript selector

 

Error, (in plot/iplot2d) cannot mix numeric and boolean arguments to min

 

with(plots)

Question:Calculating a "distance integral"

plot3d(evalf(eval(M1, Sol[1][3])), a = -1.5 .. 1.5, c = -1 .. 4, style = wireframe, color = "LightBlue", lightmodel = light3)

Warning, expecting only range variables [a, c] in expression 6.283185308*d+4.611444096 to be plotted but found name d

 

 

Sol

[[a = a, c = c, d = d]]

(11)

NULL


 

Download NonlinearFit_addon.mw

@sand15 

@WD0HHU Here is the file again!

Dear @sand15.  That looked like it was going to work but failed.  I've uploaded my version with I think is your suggested fix.  But there is something different with Maple 2026 that is causing an issue.

Thank you. 

Dear @sand15.  I tried to run your "NonlinearFit_Addon.mw" in Maple 2026 and it appears that the solve fails because it returns [].  Could this because you are using an earlier version of Maple.  

Thank you. 

@dharr Depending on the resolution of your laptop or desktop monitor, you can adjust the size of the plots with view command to fill out the plots.  This is a great illustration of the derivative of a function.  I wished I had something like this 54 years ago when I was taking freshman calculus at Purdue University.
 

restart; with(plots); s := proc (t) options operator, arrow; 2*t^4-30*t^3+135*t^2-120*t-10 end proc; diff(s(t), t); v := proc (t) options operator, arrow; diff(s(t), t) end proc; p1 := plot(s(t), t = 0 .. 8, 'gridlines', 'color' = "red", 'title' = "Plot of s(t)", background = "Azure", size = [1700, 800], axesfont = [Helvetica, bold, 14], view = [default, -100 .. 500], titlefont = [Helvetica, bold, 18], labelfont = [Helvetica, bold, 24], axis[1] = [location = low], thickness = 4, annotation = typeset("t =", ('xcoordinate')(digits = 6), " ", "  s(t)= ", ('ycoordinate')(digits = 6), " "), labels = [t, "s(t)"], labeldirections = [Horizontal, Vertical]); p2 := plot(v(t), t = 0 .. 8, 'gridlines', 'color' = "blue", 'title' = "Plot of v(t)", background = "Azure", size = [1700, 800], axesfont = [Helvetica, bold, 14], view = [default, -200 .. 300], titlefont = [Helvetica, bold, 18], labelfont = [Helvetica, bold, 24], axis[1] = [location = low], thickness = 5, annotation = typeset("t =", ('xcoordinate')(digits = 6), " ", "  v(t)= ", ('ycoordinate')(digits = 6), " "), labels = [t, "v(t)"], labeldirections = [Horizontal, Vertical]); plots:-display(Array([p1, p2]))

proc (t) options operator, arrow; 2*t^4-30*t^3+135*t^2-120*t-10 end proc

 

8*t^3-90*t^2+270*t-120

 

proc (t) options operator, arrow; diff(s(t), t) end proc

 

 

 

 

 

 

 

DocumentTools:-Tabulate([p1, p2], width = 50)


 

Download SideBySidePlotting.mw

Hello @acer! My version of Maple is `Maple 2025.2, X86 64 WINDOWS, Nov 11 2025, Build ID 1971053` and I tried to upload the file to you but somehow it did not happen.  I notice that you are using a Linux version of Maple 2025.2.  This is interestesing and a little disturbing that there are differences in the results based on whether one is using Windows versus Linux.  

Hello @acer! I tried your worksheet and I didn't get the zero on the last simplify statement.  I'll upload my worksheet.

@acer I agree with the user `nm` that the Explore command could definitely be improved.  This should be considered as a major improvement in the next upgrade to Maple.  You can't set the fonts in the sliders, for example.  Also, you can't set the font of the tick marks.  The font size is hard to read.  You can't set the font size of the value of the slider on the right.  This is not the best example of an important command like Explore.  I wish it would get improved at some point in the near future.

Dear Mr. @Lark!  Thank you so much for taking the time to tell me this.  Sometimes the Maple designers think something is "totally obvious to the most casual observer".  I never knew what this very little icon was supposed to do.  You would have thought it was a setting under "Tools" or "View" or some other straight forward location.  

Thank you again.  I almost at the end of my rope and was thinking I had to call Maple Tech Support! 

Hello @sand15! Your last 2D plot is quite aesthetically pleasing to look at with size=[1200,1200].

Thank you.

Hello @sand15! I made the one line of code change that acer suggested and it looks like it works!!

I had one question is this is more for my "feeble" eyes: Could you increase the size of the plots to size=[1200,1200]?  I can't seem to find where I can do that in your worksheet. 

Thank you.

P.S. I'll try to upload this updated worksheet but recently my uploads to MaplePrimes blog have been kicked out because it thinks I'm upload SPAM!! HA HA!!

1 2 3 4 5 Page 1 of 5