// Solve the first-order differential equation with initial value
within ModelicaByExample.BasicEquations.SimpleExample;
model FirstOrderInitial "First order equation with initial value"
Real x "State variable";
initial equation //initialization equation of variable x
x = 2"Used before simulation to compute initial values";
equation
der(x) = 1-x "Drives value of x toward 1.0";
//variable differential equation
annotation(experiment(StartTime=0,StopTime=8));
//Define the simulation start time and simulation end time, in seconds (s)
end FirstOrderInitial;
//Solve first-order differential equations at steady state start
within ModelicaByExample.BasicEquations.SimpleExample;
model FirstOrderInitial "First order equation with initial value"
Real x "State variable";
initial equation //initialization equation of variable x
der(x) = 0"Initialize the system in steady state";
//The initial tangent of the variable is the horizontal line
equation
der(x) = 1-x "Drives value of x toward 1.0";
//variable differential equation
annotation(experiment(StartTime=0,StopTime=8));
//Define the simulation start time and simulation end time, in seconds (s)
end FirstOrderInitial;
//One-dimensional Newton cooling equation
within ModelicaByExample.BasicEquations.CoolingExample;
model NewtonCooling "An example of Newton's law of cooling"
parameter Real T_inf "Ambient temperature" ;//Ambient temperature
parameter Real T0 "Initial temperature" ;//Initial temperature
parameter Real h "Convective cooling coefficient" ;//thermal convection coefficient
parameter Real A "Surface area" ;//Surface area
parameter Real m "Mass of thermal capacitance" ;//Object mass
parameter Real c_p "Specific heat" ;//The specific heat capacity of the object
Real T "Temperature" ;//Object temperature
initialequation
T = T0 "Specify initial value for T";
//object temperature
equation
m*c_p*der(T) = -h*A*(T - T_inf) "Newton's law of cooling";
end NewtonCooling;
//带类型定义的一维冷却牛顿方程
within ModelicaByExample.BasicEquations.CoolingExample;
model NewtonCoolingWithTypes "Cooling example with physical types"
// Types
type Temperature=Real(unit="K", min=0);//定义新的类型;
type ConvectionCoefficient=Real(unit="W/(m2.K)", min=0);
type Area=Real(unit="m2", min=0);
type Mass=Real(unit="kg", min=0);
type SpecificHeat=Real(unit="J/(K.kg)", min=0);
// Parameters
parameter Temperature T_inf=298.15 "Ambient temperature";
parameter Temperature T0=363.15 "Initial temperature";
parameter ConvectionCoefficient h=0.7 "Convective cooling coefficient";
parameter Area A=1.0 "Surface area";
parameter Mass m=0.1 "Mass of thermal capacitance";
parameter SpecificHeat c_p=1.2 "Specific heat";
// Variables
Temperature T "Temperature";
initial equation
T = T0 "Specify initial value for T";
equation
m*c_p*der(T) = h*A*(T_inf-T) "Newton's law of cooling";
end NewtonCoolingWithTypes;