Class: Maxima::Function
- Inherits:
-
Unit
- Object
- Unit
- Maxima::Function
show all
- Defined in:
- lib/maxima/function.rb
Constant Summary
collapse
- VARIABLE_REGEX =
This strategy fails for functions (cos etc.). However, that does not impact it’s actual usage.
/[%|a-z|A-Z]+/.freeze
- IGNORE_VARIABLES =
%w(%e %i).freeze
Instance Attribute Summary collapse
Attributes inherited from Unit
#maxima_output, #plot_title
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Unit
#===, #gnu_plot_options, #imaginary?, #inspect, #negative?, parse_float, #positive?, #real?, #simplified, #through_maxima, #to_f, #to_gnu_plot, #to_pdf, #to_s, #with_plot_title, #zero?
Constructor Details
#initialize(string, variables = nil, **options) ⇒ Function
Returns a new instance of Function.
5
6
7
8
9
10
|
# File 'lib/maxima/function.rb', line 5
def initialize(string, variables = nil, **options)
string = string.to_s
options[:maxima_output] ||= string
super(**options)
@variables = variables || Function.variables_in_string(string)
end
|
Instance Attribute Details
#string ⇒ Object
Returns the value of attribute string.
3
4
5
|
# File 'lib/maxima/function.rb', line 3
def string
@string
end
|
#variables ⇒ Object
Returns the value of attribute variables.
3
4
5
|
# File 'lib/maxima/function.rb', line 3
def variables
@variables
end
|
Class Method Details
.parse(string) ⇒ Object
Assume what we get is what we need
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/maxima/function.rb', line 45
def self.parse(string)
variables = variables_in_string(string)
if variables.any?
Function.new(string, variables)
else
Unit.parse_float(string)
end
rescue
nil
end
|
.variables_in_string(string) ⇒ Object
Instance Method Details
#==(other) ⇒ Object
87
88
89
|
# File 'lib/maxima/function.rb', line 87
def ==(other)
to_s == other.to_s
end
|
#at(v) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/maxima/function.rb', line 69
def at(v)
s = self.to_s.dup
case v
when Hash
v.each do |k,t|
k = k.to_s
if @variables.include?(k)
s.gsub!(k, "(#{t})")
end
end
else
throw :must_specify_variables_in_hash if @variables.length != 1
s.gsub!(@variables.first, "(#{v})")
end
Function.parse(s).simplified
end
|
#between(min, max, steps) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/maxima/function.rb', line 36
def between(min, max, steps)
step = (max - min).fdiv(steps)
Command.output(r: Histogram) do |c|
c.let :r, "makelist([x,float(#{self})],x, #{min}, #{max}, #{step})"
end[:r]
end
|
#definite_integral(t0, t1, v: "x") ⇒ Object
27
28
29
30
|
# File 'lib/maxima/function.rb', line 27
def definite_integral(t0, t1, v: "x")
i_v = self.integral(v: v)
i_v.at(v => t1) - i_v.at(v => t0)
end
|
#derivative(variable = nil, v: "x") ⇒ Object
32
33
34
|
# File 'lib/maxima/function.rb', line 32
def derivative(variable = nil, v: "x")
Maxima.diff(to_maxima_input, v: (variable || v))[:diff]
end
|
#gnu_plot_text ⇒ Object
57
58
59
|
# File 'lib/maxima/function.rb', line 57
def gnu_plot_text
super.gsub("^", "**")
end
|
#gnu_plot_w ⇒ Object
61
62
63
|
# File 'lib/maxima/function.rb', line 61
def gnu_plot_w
"lines"
end
|
#integral(t0 = nil, t1 = nil, v: "x") ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/maxima/function.rb', line 19
def integral(t0 = nil, t1 = nil, v: "x")
if t0 && t1
Maxima.integrate(to_maxima_input, t0, t1, v: v)[:integral]
else
Maxima.integrate(to_maxima_input, v: v)[:integral]
end
end
|
65
66
67
|
# File 'lib/maxima/function.rb', line 65
def to_maxima_input
self.to_s
end
|