Scot Gould

Scot Gould

959 Reputation

15 Badges

11 years, 338 days
Claremont McKenna, Pitzer, Scripps College
Professor of Physics
Upland, California, United States
Dr. Scot Gould is a professor of physics at Claremont McKenna, Pitzer, and Scripps Colleges - members of The Claremont Colleges in California. He was involved in the early development of the atomic force microscope. His research has included numerous studies and experiments using scanning probe microscopes, particularly those involving natural fibers such as spider silk. More recently, he was involved in developing and sustaining AISS. This full-year multi-unit, non-traditional, interdisciplinary undergraduate science education course integrated topics from biology, chemistry, physics, mathematics, and computer science. His current interest is integrating computational topics into the physics curriculum. He teaches the use of Maple's computer algebraic and numerical systems to assist students in modeling and visualizing physical and biological systems. His Dirac-notation-based quantum mechanics course is taught solely through Maple.

MaplePrimes Activity


These are answers submitted by Scot Gould

Explore procedure will not plot in MaplePrimes, so download the file.

restart

 

Basic SIR model

odes := diff(s(t), t) = -k*s(t)*i(t), diff(i(t), t) = k*s(t)*i(t)-K*i(t), diff(r(t), t) = K*i(t)

Initial condition equations where 1 = 100% of the population.  

ices := s(0) = 1-i0, i(0) = i0, r(0) = 0

 

Numerically solve with parameters to be modified later.

 

solutions := dsolve({ices, odes}, parameters = [k, K, i0], numeric, output = listprocedure)


Extract solutions

s := eval(s(t), solutions); i := eval(i(t), solutions); r := eval(r(t), solutions)

 

Simple example where
"k = 0.1, K = 0.01, i0 = 1E-10.  "

Assign the parameters some values and then plot.

solutions(parameters = [k = .1, K = 0.1e-1, i0 = 0.1e-2])

plot([s(t), i(t), r(t)], t = 0 .. 600, legend = ['s(t)', 'i(t)', 'r(t)'], thickness = [2, 4, 6])

 

Explore the results

1) Create a procedure that substitutes the values sent to it via the Explore procedure into the parameters and then plots.
2) Create an Explore of the Plot procedure.

 

Plot_SIR := proc (k0, K0, i00) solutions(parameters = [k = k0, K = K0, i0 = i00]); plot([s(t), i(t), r(t)], t = 0 .. 1000, legend = ['s(t)', 'i(t)', 'r(t)'], thickness = [2, 4, 6]) end proc

Explore(Plot_SIR(k, K, i0), parameters = [k = 0.1e-1 .. .1, K = 0.5e-2 .. 0.2e-1, i0 = 0.1e-4 .. 0.1e-2], initialvalues = [k = 0.4e-1, K = 0.16e-1, i0 = 0.5e-3])

 

Slide the sliders to vary the constants.

Download SIR_explore_example.mw

Motivated by a very old balance....
 

f := sin((a+(1/10)*a10ths+(1/100)*a100ths)*x)*exp(-(a+(1/10)*a10ths+(1/100)*a100ths)*x)

Explore(plot(f, x = 0 .. 5), parameters = [a = 0 .. 10, a10ths = 0 .. 9, a100ths = 0 .. 9], initialvalues = [a = 1, a10ths = 0, a100ths = 0])


 

Download Explore_fine_detail.mw

Your goal is to make a function from an expression. Hence, the "MakeFunction" procedure is what you need. 

restart

expression := 3.5+4.8*x

3.5+4.8*x

(1)

a := MakeFunction(3.5+4.8*x, x)

proc (x) options operator, arrow; 3.5+4.8*x end proc

(2)

a(24)

118.7

(3)

b := MakeFunction(expression, x)

proc (x) options operator, arrow; 3.5+4.8*x end proc

(4)

b(24)

118.7

(5)

NULL

Download MakeFunction.mw

This may be the single greatest procedure Maplesoft has created in decades. (Available only on version 2023 and greater. So, pay for the upgrade if you can. If you can't, create an alias, alias(MakeFunction = unapply)

Since I don't know what this looks like, let's make a collection of space curve.

 

Copy your text data:

 

restart; xData := [0., 0.4995839572e-1*sin(x), 0.9966865249e-1*sin(x), .1488899476*sin(x), .1973955598*sin(x), .2449786631*sin(x), .2914567945*sin(x), .3366748194*sin(x), .3805063771*sin(x), .4228539261*sin(x), .4636476090*sin(x), .5028432109*sin(x), .5404195003*sin(x), .5763752206*sin(x), .6107259644*sin(x), .6435011088*sin(x), .6747409422*sin(x), .7044940642*sin(x), .7328151018*sin(x), .7597627549*sin(x), .7853981634*sin(x)]


Match with t with the same number of point.

tData := [seq(0.5e-1*n, n = 0 .. upperbound(xData)-1)]

 

Create a function (using the older version of the MakeFunction procedure) from the data:

 

xtPoint := unapply([x, xData[n], tData[n]], x, n)

And from each point, make a spaaaaace curve.

 

xtLine := unapply([seq(xtPoint(x, n), n = 1 .. upperbound(tData))], x)

 

Next, a generic plot of a collection of space curves

 

plots:-spacecurve(xtLine(x), x = -Pi .. Pi, size = [500, 500], color = "xkcd:blue", thickness = 3, labels = ["x", "xData", "tData"], labelfont = ["Times New Roman", 15], orientation = [84, 21, 160])

 


Low-budget version of 3D surface data.

 

Creating a sequence of points without the option numpoints in the sequence function.

From it, we make "Let's go surfing now; everybody is learning how" data.

N := 100; x0 := -Pi; xf := Pi; dX := (xf-x0)/(N-1); surfData := [seq(xtLine(dX*n+x0, round(n*upperbound(xData)/N+1)), n = 0 .. N-1)]

And plot

 

plots:-surfdata(surfData, labels = ["x", "xData", "tData"], labelfont = ["Times New Roman", 15], orientation = [84, 21, 160], size = [500, 500])

 

Note bug in 3D plot. Need to report.

``


 

Download My_3d_plot.mw

Of course, if you don't understand how to use the palettes, that is a different issue. 

Write out A^T as B and each component of the matrix.

 

restart; B := Matrix(2, 2, {(1, 1) = a__11, (1, 2) = a__21, (2, 1) = a__12, (2, 2) = a__22}); I2x2 := Matrix(2, 2, {(1, 1) = 1, (1, 2) = 0, (2, 1) = 0, (2, 2) = 1}); equation1 := 4/(B+2*I2x2) = (Matrix(2, 2, {(1, 1) = 1, (1, 2) = 1, (2, 1) = -3/2, (2, 2) = 1/2}))

Matrix(2, 2, {(1, 1) = a__11, (1, 2) = a__21, (2, 1) = a__12, (2, 2) = a__22})

 

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

 

Matrix(%id = 36893490656581279980) = Matrix(%id = 36893490656581280100)

(1)

 

Solve for each component.

 

answer := solve(equation1, {a__11, a__12, a__21, a__22})

{a__11 = -1, a__12 = 3, a__21 = -2, a__22 = 0}

(2)

 

Assign each component the value in answer and then write out A

 

assign(answer); A := Matrix(2, 2, {(1, 1) = a__11, (1, 2) = a__12, (2, 1) = a__21, (2, 2) = a__22})

Matrix(%id = 36893490656581256964)

(3)

NULL


Download Matrix_Question.mw

Windows: From the menu bar, select Tools followed by Options

Mac: Select Preferences from the menu bar. 

On the first tab, at the bottom of the display, search for auto save every X minutes. Personally, I turn off keep files. I want to keep only those files for which Maple was shut down mid-calculation.  

 

Check out shortcuts in help. Ctrl-d might work since it deletes all output.

Export has a problem in Windows that is corrected by choosing to print to a PDF. Not as convenient, but it fixes the problem. I suggest you try that.

I prefer to use the elementwise operator ~. I find it more readable than using map.

outList := lhs~(eq1)

 

My guess is that the variable x has been assigned a value of 1.71. So, use a different variable in your plot

  plot(f(x1), x1 = -0.667 .. 1.71, -5..20, gridlines)

No need to label the vertical axis because it really isn't the variable in the vertical direction. 

The magenta error of death tells us the equation in fsolve is being evaluated before it is ever used. Put a single quote around the equation in fsolve and it will work.

h := y -> fsolve( ' f(x__0) = y', x__0 = Range)

I can empathize. Students in my class last week struggled with the same issue.  

For them, it was applying the slope (Euler's) numerical method to solve an ordinary

differential equation. If the endpoints were exact, such as 0 and 2, the looping took

forever. However, if the endpoints were floating point approximations such as 0.0

and/or 2.0, the calculations were instantaneous.

Because of these struggles, it has become ingrained in their head they must enter

constants in numerical calculations as floating-point numbers. And maybe that is

the best one can hope for since I agree with others, there probably is no way to

force Maple to see all numbers as approximations.

Regarding integrals, there is no need to memorize evalf or the option numeric.

Simply set the endpoints to floating point numbers, and Maple will generate a

floating point outcome. For example:

 

Exact integral:

int(exp(-x^2), x = 0 .. infinity)

(1/2)*Pi^(1/2)

(1)

 

Using the floating-point approximation.

int(exp(-x^2), x = 0. .. infinity)

.8862269255

(2)

   ``

Download Forcing_floating_point_approximations.mw

It is my experience that full-precision equations usually lead to full-precision answers, if possible.  If you prefer a "floating point approximation", change one of the numbers from a whole number in your equation to a floating point value. For example, 4 to 4. or 4.0.  Maple will report a floating point result. 

If you don't obtain a floating point result after making the modification, as suggested, take the result and evaluate it to a floating point value using the evalf procedure. 

It is late, so the experts probably are asleep. Here is a quick reply.

 

As I read what you uploaded, the PDE is not a PDE but a 2nd order ODE with a parameter k in the initial conditions.

 

restart; interface(imaginaryunit = 'I')

Rewriting the PDE as an ODE for which the variable u is a function of time:

ode := (10*I)*(diff(u(t), t))+diff(u(t), t, t)-16*u(t) = 0

And setting the initial conditions at t = 0

ices := u(0) = sqrt((1/2)*Pi)*csch((1/2)*Pi*k), (D(u))(0) = -(1/4)*sqrt(2)*Pi^(3/2)*csch((1/2)*Pi*k)*coth((1/2)*Pi*k)

Solve numerically, but let k be a floating parameter one can adjust on the fly:

 

sols := dsolve({ices, ode}, numeric, output = listprocedure, parameters = [k])

Extracting out the variables:

u := eval(u(t), sols); u_dot := eval(diff(u(t), t), sols)

 

Since k can be anything but appears to be somewhere between 0 and 100, make a plotting procedure that plots the magnitude of u and the u-dot for "t = 0 to 1." (Both variables are complex, so adjust to suit your interest.)

 

"PlotVariables := proc(k::float)        global sols, u, u_dot;         sols(parameters = [k]);         plot([|u(t)|, |u_dot(t)|], t= 0..1, legend = ['u', '(u)']);     end proc:  "

Now explore:

Explore(PlotVariables(k), parameters = [k = 0 .. 100.0], initialvalues = [k = 50.0])

Play with the slider and satisfy the other conditions.

 


 

Download ODE_or_PDE_solution.mw

Try this help page to load the suggested commands:

https://www.maplesoft.com/support/help/maple/view.aspx?path=worksheet%2Freference%2Finitialization

3 4 5 6 7 8 9 Page 5 of 9