Samir Khan

1744 Reputation

19 Badges

14 years, 155 days

My role is to help customers better exploit our tools. I’ve worked in selling, supporting and marketing maths and simulation software for all my professional career.

I’m fascinated by the full breadth and range of application of Maple. From financial mathematics and engineering to probability and calculus, I’m always impressed by what our users do with our tools.

However much I strenuously deny it, I’m a geek at heart. My first encounter with Maple was as an undergraduate when I used it to symbolically solve the differential equations that described the heat transfer in a series of stirred tanks. My colleagues brute-forced the problem with a numerical solution in Fortran (but they got the marks because that was the point of the course). I’ve since dramatized the process in a worksheet, and never fail to bore people with the story behind it.

I was born, raised and spent my formative years in England’s second city, Birmingham. I graduated with a degree in Chemical Engineering from The University of Nottingham, and after completing a PhD in Fluid Dynamics at Herriot-Watt University in Edinburgh, I started working for Adept Scientific – Maplesoft’s partner in the UK.

MaplePrimes Activity

These are answers submitted by Samir Khan

The Tire Library only models motion on flat surfaces. 


Check out this post and this application for some modeling tips. On an initial reading, your system appears tractable.

Break down the problem into two parts.  Consider each section (for insulation 1 and insulation 2) separately. For each section you need three PDEs (one each for the temperature profile of the liquid in the pipe, the steel pipe wall, and the insulation).

Consider a section dx, and perform a heat balance for the liquid in the pipe, the tube wall and the insulation.

For the liquid in the pipe you'll have terms for the accumulation of heat, heat supplied by liquid flowing in and heat supplied by liquid flowing out, and heat transfer to the tube wall.

For the steel tube wall, you'll have terms for the accumulation of heat, heat flowing into and out of adjacent tube wall sections (Fourier Law), heat transfered from the tube-side liquid and heat exiting to the insulation.

For the insulation, you'll have terms for the accumulation of heat, heat flowing into and out of adjacent insulation sections (Fourier Law), heat entering from the steel wall, and heat exiting to the cold water


Examine the non-linear spring-mass-damper model that ships with MapleSim.  It demonstrates how you can vary spring and damping constants during a simulation.


As far as I understand, variable time delay (in a manner meaningful for dynamic simulation) requires support for delay differential equations. This is scheduled for a future version of MapleSim


If you simpy want to drive the MapleSim model from the data generated by the hardware equipment, then

  • Save the data from your hardware system into a text file,
  • attached it to your MapleSim model,
  • and then reference the data in an interpolation component (Signal Blocks > Interpolation Tables)


I've succesfully used the Sockets package to send emails from a Maple worksheet.  You'll need a locally installed SMTP server (I've used QK SMTP Server and Free SMTP Server but other tools are available)

Once you have an SMTP server running and accepting messages from localhost on port 25, execute the following code in a Maple worksheet (changing the references to my email address and message body, of course)

sid:=Open("localhost",25 ):
Write(sid,"HELO localhost\n"):
Write(sid,"MAIL FROM:<>\n"):
Write(sid,"RCPT TO:<>\n"):
Write(sid,"From: ""Samir Khan"" <>\nTo: ""Samir Khan"" <>\nSubject: Email From Maple\n\nThis is the body of the email. I'm sending an email from Maple!\n\n.\n"):

This works perfectly when I try this from the Maplesoft office with an email succesfully received (after making the appropriate changes to myemail and toemail), but not with my home ISP. I'm not an expert in these matters so I can't tell you why.


The behaviour of the Code Edit region is by design.  ?CodeEditRegion explains that when the region is collapsed,

...all but the first line of the procedure will be suppressed. The first line of the procedure displays to the right of the icon. A comment may be included before the procedure to display a descriptive heading instead of the first line of the procedure. To suppress the full procedure, insert a pound character (#) on its own line before the procedure



Here's a quick and dirty translation of 5.2.pdf to Maple.

I haven't done any detailed checking or used units - this was just a first pass conversion

The heat loss Q would be proportional to delta T.  It wouldn't be constant.

The box will lose heat by conduction to the outside world

A better model may be to connect the following blocks together.

Fixed Temperature - Thermal Conductor - Heat Capacitor


1) Assuming that the data from the procedure is assinged to str, then the following hacky code lifted from the Stock Import worksheet works (which was incidently written at 3am in the morning during a thunderstorm - hence the hackiness)

strLength := StringTools[Length](str):
start := StringTools[Search]("Adj Close", str)+10:
str2 := StringTools[SubString](str, start .. strLength):
newlines := StringTools[SearchAll]("\n", str2):
days := nops([newlines]):
commas := StringTools[SearchAll](",", str2):
pos := sort([1, commas, newlines, StringTools[Length](str2)]):
data := Matrix(days, 7):
k := 1:
for i to days do
   for j to 7 do
      if k < nops(pos) then
         str3 := StringTools[SubString](str2, pos[k] .. pos[k+1]):
         strAscii := convert(str3, bytes):
         strAscii := remove(has, strAscii, 10):
         strAscii := remove(has, strAscii, 44):
         strAscii := remove(has, strAscii, 13):
         strAscii := remove(has, strAscii, 34):
         strClean := convert(strAscii, bytes):
         if j <> 1 then
            data[i, j] := parse(strClean)
            data[i, j] := strClean
         end if;
      k := k+1
      end if
   end do
end do:




One way of doing this is in a Maple document attached to a MapleSim model.

 * Let say that you have a MapleSim model that returns 4 plots

* Attach say the Equations template to the MapleSim model

*Scroll to the bottom and execute the following commands

> with(DocumentTools); with(MapleSim); with(plots);
> theModel := GetProperty(Simulation0, system);

the following command returns an array; the first column is time, and the remaing columns are all probe values.
> data := RunSimulation(theModel, output = datapoint, returnTimeData);

Hence to plot the first probe value against time for the whole range (assuming 200 points in total)
> plotdata := [seq([data[i, 1], data[i, 2]], i = 1 .. 200)];
> pointplot(plotdata);

To plot all the probes over a specific time range
> plotdata := seq(pointplot([seq([data[i, 1], data[i, j]], i = 150 .. 175)], connect = true), j = 2 .. 5);
> display(Array([plotdata]));

Please see the attached MapleSim model for a worked example, and let us know if you have any questions.

View file details

Add method=branchandbound to the GlobalSolve command, i.e.

GlobalSolve(add(Difference[p]^2,p=1..6), op(VarRanges), method=branchandbound);

It's now insensitive to your search range.  The default method is multistart.


1 2 3 Page 3 of 3