Class: Maxima::Unit
- Inherits:
-
Object
show all
- Defined in:
- lib/maxima/unit.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(inline_maxima_output = nil, plot_title: nil, maxima_output: nil) ⇒ Unit
Returns a new instance of Unit.
5
6
7
8
|
# File 'lib/maxima/unit.rb', line 5
def initialize(inline_maxima_output = nil, plot_title: nil, maxima_output: nil)
@maxima_output = inline_maxima_output || maxima_output
@plot_title = plot_title
end
|
Instance Attribute Details
#maxima_output ⇒ Object
Returns the value of attribute maxima_output.
3
4
5
|
# File 'lib/maxima/unit.rb', line 3
def maxima_output
@maxima_output
end
|
#plot_title ⇒ Object
Returns the value of attribute plot_title.
3
4
5
|
# File 'lib/maxima/unit.rb', line 3
def plot_title
@plot_title
end
|
Class Method Details
.parse(m) ⇒ Object
18
19
20
|
# File 'lib/maxima/unit.rb', line 18
def self.parse(m)
Function.parse(m)
end
|
Instance Method Details
#==(other) ⇒ Object
107
108
109
|
# File 'lib/maxima/unit.rb', line 107
def ==(other)
(self <=> other) == 0
end
|
#===(other) ⇒ Object
True mathematical equivalence
112
113
114
|
# File 'lib/maxima/unit.rb', line 112
def ===(other)
(self == other) || Maxima.equivalence(self, other)[:is_equal]
end
|
#at(_) ⇒ Object
59
60
61
|
# File 'lib/maxima/unit.rb', line 59
def at(_)
self
end
|
#gnu_plot_options ⇒ Object
72
73
74
75
76
|
# File 'lib/maxima/unit.rb', line 72
def gnu_plot_options
{ w: gnu_plot_w }.tap do |options|
options[:plot_title] = @plot_title if @plot_title
end
end
|
#gnu_plot_text ⇒ Object
68
69
70
|
# File 'lib/maxima/unit.rb', line 68
def gnu_plot_text
to_s
end
|
#gnu_plot_w ⇒ Object
78
79
80
|
# File 'lib/maxima/unit.rb', line 78
def gnu_plot_w
"points"
end
|
90
91
92
|
# File 'lib/maxima/unit.rb', line 90
def imaginary?
throw "imaginary_is_undecidable_for_#{self.class}"
end
|
#inspect ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/maxima/unit.rb', line 10
def inspect
if plot_title.nil? || plot_title == ""
"#{self.class}(#{self})"
else
"#{self.class}[#{plot_title}](#{self})"
end
end
|
102
103
104
|
# File 'lib/maxima/unit.rb', line 102
def negative?
to_f < 0
end
|
94
95
96
|
# File 'lib/maxima/unit.rb', line 94
def positive?
to_f > 0
end
|
86
87
88
|
# File 'lib/maxima/unit.rb', line 86
def real?
throw "real_is_undecidable_for_#{self.class}"
end
|
#simplified ⇒ Object
40
41
42
|
# File 'lib/maxima/unit.rb', line 40
def simplified
@simplified ||= through_maxima(:expand)
end
|
#through_maxima(*array_options, **options) ⇒ Object
~~ *unary_operations, **unary_operations_options
45
46
47
48
49
|
# File 'lib/maxima/unit.rb', line 45
def through_maxima(*array_options, **options)
@after_maxima ||= Command.output(itself: Unit) do |c|
c.let :itself, self.to_s, *array_options, **options
end[:itself]
end
|
#to_f ⇒ Object
82
83
84
|
# File 'lib/maxima/unit.rb', line 82
def to_f
throw "cannot_cast_#{self.class}_to_float"
end
|
#to_gnu_plot ⇒ Object
55
56
57
|
# File 'lib/maxima/unit.rb', line 55
def to_gnu_plot
[gnu_plot_text, gnu_plot_options]
end
|
51
52
53
|
# File 'lib/maxima/unit.rb', line 51
def to_maxima_input
to_s
end
|
#to_pdf(t0, t1, v: "x") ⇒ Object
63
64
65
|
# File 'lib/maxima/unit.rb', line 63
def to_pdf(t0, t1, v: "x")
(self / integral(t0, t1)).definite_integral(t0, v)
end
|
#to_s ⇒ Object
26
27
28
|
# File 'lib/maxima/unit.rb', line 26
def to_s
@maxima_output
end
|
#with_plot_title(plot_title) ⇒ Object
30
31
32
|
# File 'lib/maxima/unit.rb', line 30
def with_plot_title(plot_title)
self.class.new(@maxima_output, plot_title)
end
|
98
99
100
|
# File 'lib/maxima/unit.rb', line 98
def zero?
to_f == 0
end
|