4 people like it.

# Solve ODE - Newton's Law of Cooling & Charting using Plotly

Solve Ordinary Differential Equation Newton's Law of Cooling Chart using Plotly The object will eventually reach room temperature after a period of time

 ``` 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: ``` ``````#r "MathNet.Numerics.dll" #r "MathNet.Numerics.FSharp.dll" open MathNet.Numerics #r "FSharp.Plotly.dll" open FSharp.Plotly open System // Newton's Law of Cooling // Te = Environment Temperature // T(t) = Object Temperature at time t // c = Heat Transfer Coefficient // T' = c ( Te - T ) let heatTransferCoefficient, environmentTemperature = 2.0, 25.0 let T' = Func (fun t T -> heatTransferCoefficient * ( environmentTemperature - T )) let endTime, timeStep = 5.0, 0.05 let minTemp, maxTemp = 0.0, 50.0 [| let t = [| 0.0 .. timeStep .. endTime |]; [| for i in minTemp .. 10.0 .. maxTemp do let f = OdeSolvers.AdamsBashforth.FourthOrder( i, t.[0], endTime , t.Length, T' ) yield Chart.Line ( t, f ) |] [| for i = 1 to int maxTemp / 10 - 1 do let t = [| float i .. timeStep .. endTime |] let f1 = OdeSolvers.AdamsBashforth.FourthOrder( minTemp, t.[0], endTime , t.Length, T' ) let f2 = OdeSolvers.AdamsBashforth.FourthOrder( maxTemp, t.[0], endTime , t.Length, T' ) yield! [| Chart.Line ( t, f1 ); Chart.Line ( t, f2 ) |] |] |] |> Array.concat |> Chart.Combine |> Chart.withLegend false |> Chart.withShape( Shape.init( StyleParam.ShapeType.Line, 0.0, endTime , environmentTemperature, environmentTemperature ) ) |> Chart.withTitle "Newton's Law of Cooling" |> Chart.withX_AxisStyle "Time" |> Chart.withY_AxisStyle "Temperature" |> Chart.withSize ( 1000.0, 1000.0 ) |> Chart.Show ``````
namespace MathNet
namespace MathNet.Numerics
Multiple items
namespace FSharp

--------------------
namespace Microsoft.FSharp
namespace FSharp.Plotly
namespace System
val heatTransferCoefficient : float
val environmentTemperature : float
val T' : Func<float,float,float>
Multiple items
type Func<'TResult> =
delegate of unit -> 'TResult

--------------------
type Func<'T,'TResult> =
delegate of 'T -> 'TResult

--------------------
type Func<'T1,'T2,'TResult> =
delegate of 'T1 * 'T2 -> 'TResult

--------------------
type Func<'T1,'T2,'T3,'TResult> =
delegate of 'T1 * 'T2 * 'T3 -> 'TResult

--------------------
type Func<'T1,'T2,'T3,'T4,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 -> 'TResult

--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 -> 'TResult

--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 -> 'TResult

--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 -> 'TResult

--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 -> 'TResult

--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 -> 'TResult

--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 -> 'TResult

--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 -> 'TResult

--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 -> 'TResult

--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12,'T13,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 * 'T13 -> 'TResult

--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12,'T13,'T14,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 * 'T13 * 'T14 -> 'TResult

--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12,'T13,'T14,'T15,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 * 'T13 * 'T14 * 'T15 -> 'TResult

--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12,'T13,'T14,'T15,'T16,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 * 'T13 * 'T14 * 'T15 * 'T16 -> 'TResult
Multiple items
val float : value:'T -> float (requires member op_Explicit)

--------------------
type float = Double

--------------------
type float<'Measure> = float
val t : float
val T : float
val endTime : float
val timeStep : float
val minTemp : float
val maxTemp : float
val t : float []
val i : float
val f : float []
namespace MathNet.Numerics.OdeSolvers
static member FirstOrder : y0:float * start:float * end:float * N:int * f:Func<float, float, float> -> float[]
static member FourthOrder : y0:float * start:float * end:float * N:int * f:Func<float, float, float> -> float[]
static member SecondOrder : y0:float * start:float * end:float * N:int * f:Func<float, float, float> -> float[]
static member ThirdOrder : y0:float * start:float * end:float * N:int * f:Func<float, float, float> -> float[]
OdeSolvers.AdamsBashforth.FourthOrder(y0: float, start: float, end: float, N: int, f: Func<float,float,float>) : float []
type Chart =
static member Area : xy:seq<#IConvertible * #IConvertible> * ?Name:string * ?ShowMarkers:bool * ?Showlegend:bool * ?MarkerSymbol:Symbol * ?Color:'a2 * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?Dash:DrawingStyle * ?Width:'a4 -> GenericChart
static member Area : x:seq<#IConvertible> * y:seq<#IConvertible> * ?Name:string * ?ShowMarkers:bool * ?Showlegend:bool * ?MarkerSymbol:Symbol * ?Color:'a2 * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?Dash:DrawingStyle * ?Width:'a4 -> GenericChart
static member Bar : keysvalues:seq<#IConvertible * #IConvertible> * ?Name:string * ?Showlegend:bool * ?Color:'a2 * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?Marker:Marker -> GenericChart
static member Bar : keys:seq<#IConvertible> * values:seq<#IConvertible> * ?Name:string * ?Showlegend:bool * ?Color:'a2 * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?Marker:Marker -> GenericChart
static member BoxPlot : xy:seq<'a0 * 'a1> * ?Name:string * ?Showlegend:bool * ?Color:'a2 * ?Fillcolor:'a3 * ?Opacity:float * ?Whiskerwidth:'a4 * ?Boxpoints:Boxpoints * ?Boxmean:BoxMean * ?Jitter:'a5 * ?Pointpos:'a6 * ?Orientation:Orientation -> GenericChart
static member BoxPlot : ?x:'a0 * ?y:'a1 * ?Name:string * ?Showlegend:bool * ?Color:'a2 * ?Fillcolor:'a3 * ?Opacity:float * ?Whiskerwidth:'a4 * ?Boxpoints:Boxpoints * ?Boxmean:BoxMean * ?Jitter:'a5 * ?Pointpos:'a6 * ?Orientation:Orientation -> GenericChart
static member Bubble : xysizes:seq<#IConvertible * #IConvertible * #IConvertible> * ?Name:string * ?Showlegend:bool * ?MarkerSymbol:Symbol * ?Color:'a3 * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font -> GenericChart
static member Bubble : x:seq<#IConvertible> * y:seq<#IConvertible> * sizes:seq<#IConvertible> * ?Name:string * ?Showlegend:bool * ?MarkerSymbol:Symbol * ?Color:'a3 * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font -> GenericChart
static member ChoroplethMap : locations:seq<string> * z:seq<#IConvertible> * ?Text:seq<#IConvertible> * ?Locationmode:LocationFormat * ?Autocolorscale:bool * ?Colorscale:Colorscale * ?Colorbar:'a2 * ?Marker:Marker * ?Zmin:'a3 * ?Zmax:'a4 -> GenericChart
static member Column : keysvalues:seq<#IConvertible * #IConvertible> * ?Name:string * ?Showlegend:bool * ?Color:'a2 * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?Marker:Marker -> GenericChart
...
static member Chart.Line : xy:seq<#IConvertible * #IConvertible> * ?Name:string * ?ShowMarkers:bool * ?Showlegend:bool * ?MarkerSymbol:StyleParam.Symbol * ?Color:'a2 * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:StyleParam.TextPosition * ?TextFont:Font * ?Dash:'a4 * ?Width:'a5 -> GenericChart.GenericChart
static member Chart.Line : x:seq<#IConvertible> * y:seq<#IConvertible> * ?Name:string * ?ShowMarkers:bool * ?Showlegend:bool * ?MarkerSymbol:StyleParam.Symbol * ?Color:'c * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:StyleParam.TextPosition * ?TextFont:Font * ?Dash:'e * ?Width:'f -> GenericChart.GenericChart
val i : int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int
val f1 : float []
val f2 : float []
type Array =
member Clone : unit -> obj
member CopyTo : array:Array * index:int -> unit + 1 overload
member GetEnumerator : unit -> IEnumerator
member GetLength : dimension:int -> int
member GetLongLength : dimension:int -> int64
member GetLowerBound : dimension:int -> int
member GetUpperBound : dimension:int -> int
member GetValue : [<ParamArray>] indices:int[] -> obj + 7 overloads
member Initialize : unit -> unit
member IsFixedSize : bool
...
val concat : arrays:seq<'T []> -> 'T []
static member Chart.Combine : gCharts:seq<GenericChart.GenericChart> -> GenericChart.GenericChart
static member Chart.withLegend : showlegend:bool -> (GenericChart.GenericChart -> GenericChart.GenericChart)
static member Chart.withShape : shape:Shape -> (GenericChart.GenericChart -> GenericChart.GenericChart)
Multiple items
type Shape =
inherit DynamicObj
new : unit -> Shape
static member init : ?ShapeType:ShapeType * ?X0:'a * ?X1:'b * ?Y0:'c * ?Y1:'d * ?Path:'e * ?Opacity:'f * ?Line:Line * ?Fillcolor:'g * ?Layer:Layer * ?Xref:'h * ?Yref:'i -> Shape
static member style : ?ShapeType:ShapeType * ?X0:'a0 * ?X1:'a1 * ?Y0:'a2 * ?Y1:'a3 * ?Path:'a4 * ?Opacity:'a5 * ?Line:Line * ?Fillcolor:'a6 * ?Layer:Layer * ?Xref:'a7 * ?Yref:'a8 -> (Shape -> Shape)

--------------------
new : unit -> Shape
static member Shape.init : ?ShapeType:StyleParam.ShapeType * ?X0:'a * ?X1:'b * ?Y0:'c * ?Y1:'d * ?Path:'e * ?Opacity:'f * ?Line:Line * ?Fillcolor:'g * ?Layer:StyleParam.Layer * ?Xref:'h * ?Yref:'i -> Shape
module StyleParam

from FSharp.Plotly
type ShapeType =
| Circle
| Rectangle
| SvgPath
| Line
static member convert : (ShapeType -> obj)
static member toString : (ShapeType -> string)
union case StyleParam.ShapeType.Line: StyleParam.ShapeType
static member Chart.withTitle : title:string * ?Titlefont:Font -> (GenericChart.GenericChart -> GenericChart.GenericChart)
static member Chart.withX_AxisStyle : title:'a * ?MinMax:(float * float) * ?Showgrid:'b * ?Showline:'c * ?Side:StyleParam.Side * ?Overlaying:StyleParam.AxisAnchorId * ?Id:int * ?Domain:(float * float) * ?Position:float * ?Anchor:StyleParam.AxisAnchorId -> (GenericChart.GenericChart -> GenericChart.GenericChart)
static member Chart.withY_AxisStyle : title:'a * ?MinMax:(float * float) * ?Showgrid:'b * ?Showline:'c * ?Side:StyleParam.Side * ?Overlaying:StyleParam.AxisAnchorId * ?Id:int * ?Domain:(float * float) * ?Position:float * ?Anchor:StyleParam.AxisAnchorId -> (GenericChart.GenericChart -> GenericChart.GenericChart)
static member Chart.withSize : width:float * heigth:float -> (GenericChart.GenericChart -> GenericChart.GenericChart)
static member Chart.Show : ch:GenericChart.GenericChart -> unit