-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbode.dart
More file actions
77 lines (62 loc) · 1.53 KB
/
bode.dart
File metadata and controls
77 lines (62 loc) · 1.53 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import 'dart:io';
import 'params.dart';
/* https://matheplanet.com/default3.html?call=article.php?sid=1358 */
void bode(
var exp, {
var laplace='s',
var format='png',
var labels=Labels.defaultLabels(),
var frm=0.01,
var to=100000.0,
var showGrid=false,
var out="bode",
var width=640,
var height=480,
var scale=1
})
{
exp = exp.replaceAll(laplace, '{0,1}*$laplace');
var str = "" +
"set terminal $format size ${width*scale},${height*scale};" +
"set output '$out.$format';"+
"A($laplace) = $exp;"+
"set dummy $laplace;"+
"set multiplot layout 2,1;"+
"unset xlabel;"+
"set grid x;"+
"set logscale x;"+
"set xrange [$frm : $to];"+
"set ytics nomirror;"+
"set autoscale y;"+
"set xzeroaxis;"+
"set format x '';"+
"set tmargin at screen 0.95;"+
"set bmargin at screen 0.51;"+
"set ylabel \"${labels.ylabel}\";"+
"set title \" ${labels.title }\";"+
"plot 20*log10(abs(A($laplace)));"+
"set format x '10^{%L}';"+
"set tmargin at screen 0.49;"+
"set bmargin at screen 0.05;"+
"set xlabel \"${labels.xlabel}\";"+
"set ylabel \"${labels.xlabel}\";"+
"plot 180/pi*arg(A($laplace));"+
"unset multiplot;"+
"set output;";
Process.start('gnuplot', ["-e", str]);
}
String fromCoefs(
var num,
var den)
{
var str = "(";
for ( var i = 0; i<num.length-1; i++)
str+="${num[i]}*s**${num.length-1-i}+";
str+=(num[num.length-1]==0?'0':'1');
str += ")/(";
for ( var i = 0; i<den.length-1; i++)
str+="${den[i]}*s**${den.length-1-i}+";
str+=(den[den.length-1]==0?'0':'1');
str += ")";
return str;
}