Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
44
Task/Euler-method/Dart/euler-method.dart
Normal file
44
Task/Euler-method/Dart/euler-method.dart
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import 'dart:math';
|
||||
import "dart:io";
|
||||
|
||||
const double k = 0.07;
|
||||
const double initialTemp = 100.0;
|
||||
const double finalTemp = 20.0;
|
||||
const int startTime = 0;
|
||||
const int endTime = 100;
|
||||
|
||||
void ivpEuler(double Function(double, double) function, double initialValue, int step) {
|
||||
stdout.write(' Step ${step.toString().padLeft(2)}: ');
|
||||
var y = initialValue;
|
||||
for (int t = startTime; t <= endTime; t += step) {
|
||||
if (t % 10 == 0) {
|
||||
stdout.write(y.toStringAsFixed(3).padLeft(7));
|
||||
}
|
||||
y += step * function(t.toDouble(), y);
|
||||
}
|
||||
print('');
|
||||
}
|
||||
|
||||
void analytic() {
|
||||
stdout.write(' Time: ');
|
||||
for (int t = startTime; t <= endTime; t += 10) {
|
||||
stdout.write(t.toString().padLeft(7));
|
||||
}
|
||||
stdout.write('\nAnalytic: ');
|
||||
for (int t = startTime; t <= endTime; t += 10) {
|
||||
var temp = finalTemp + (initialTemp - finalTemp) * exp(-k * t);
|
||||
stdout.write(temp.toStringAsFixed(3).padLeft(7));
|
||||
}
|
||||
print('');
|
||||
}
|
||||
|
||||
double cooling(double t, double temp) {
|
||||
return -k * (temp - finalTemp);
|
||||
}
|
||||
|
||||
void main() {
|
||||
analytic();
|
||||
ivpEuler(cooling, initialTemp, 2);
|
||||
ivpEuler(cooling, initialTemp, 5);
|
||||
ivpEuler(cooling, initialTemp, 10);
|
||||
}
|
||||
40
Task/Euler-method/MATLAB/euler-method.m
Normal file
40
Task/Euler-method/MATLAB/euler-method.m
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
clear all;close all;clc;
|
||||
format longG;
|
||||
|
||||
% Main Script
|
||||
for h = [5, 10]
|
||||
fprintf('Step %d:\n\n', h);
|
||||
tabular(15, 'Time', 'Euler', 'Analytic');
|
||||
T0 = 100.0;
|
||||
t0 = 0;
|
||||
t1 = 100;
|
||||
T = euler(@(T) -0.07 * (T - 20.0), T0, t0, t1, h);
|
||||
for i = 1:length(T)
|
||||
t = (i-1) * h;
|
||||
analytic = 20.0 + 80.0 * exp(-0.07 * t);
|
||||
tabular(15, t, round(T(i), 6), round(analytic, 6));
|
||||
end
|
||||
fprintf('\n');
|
||||
end
|
||||
|
||||
function T = euler(f, T0, t0, t1, h)
|
||||
% EULER A simple implementation of Euler's method for solving ODEs
|
||||
% f - function handle for the derivative
|
||||
% T0 - initial temperature
|
||||
% t0, t1 - start and end times
|
||||
% h - step size
|
||||
T = T0;
|
||||
for t = t0:h:t1
|
||||
T(end+1) = T(end) + h * f(T(end));
|
||||
end
|
||||
end
|
||||
|
||||
function tabular(width, varargin)
|
||||
% TABULAR Prints a series of values in a tabular form
|
||||
% width - cell width
|
||||
% varargin - variable number of arguments representing cells
|
||||
for i = 1:length(varargin)
|
||||
fprintf('%-*s', width, num2str(varargin{i}));
|
||||
end
|
||||
fprintf('\n');
|
||||
end
|
||||
22
Task/Euler-method/Uiua/euler-method.uiua
Normal file
22
Task/Euler-method/Uiua/euler-method.uiua
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
"Euler Solution"
|
||||
T ← 100 # initial starting temp
|
||||
TR ← 20 # room temp
|
||||
TMINUSTR ← - TR T
|
||||
h ← 10 # step size
|
||||
k ← 0.07 # coefficent
|
||||
TEND ← 100 # end time
|
||||
n ← ÷ h 100 # steps
|
||||
# inital starting point
|
||||
T
|
||||
.
|
||||
# .. clone the top of stack and take if for next step
|
||||
# repeat the steps n times with ⍥
|
||||
Solution ← [⍥(.. - × h × k - TR)]+ n 1
|
||||
⇌ ⊂ Solution T
|
||||
|
||||
# analytical solution
|
||||
"Analytical Solution"
|
||||
# apply function to LIST
|
||||
List ← × k × h ⇡n
|
||||
# Analytical solution applied
|
||||
+ TR × TMINUSTR ⁿ ¯List e
|
||||
Loading…
Add table
Add a link
Reference in a new issue