目标:使用非线性函数绘制图形。函数和图表
这是我第一次在 Octave 工作。要绘制图表,我需要计算 Fx (0.1 ... 10) 范围内的函数。
我试图通过 for 循环循环函数来实现这一点,将结果写入数组(x 轴 - Fn,y 轴 - 函数值),然后将数组加载到 plot() 函数中。
Fn = 1
Ln = 5
Q = 0.5
function retval = test (Fn, Ln, Q)
# Fn squared (for common used)
Fn = Fn^2
# Node A + Node B
nodeA = Fn * (Ln - 1)
nodeB = (Ln * Fn - 1)^2 + Fn * (Fn - 1)^2 * (Ln - 1)^2 * Q^2
nodeB = sqrt(nodeB)
# Result
result = nodeA / nodeB
retval = result
return;
endfunction
frequencyArray = {}
gainArray = {}
fCount = 1
gCount = 1
for i = 0:0.5:5
# F
Fn = i
frequencyArray{fCount} = Fn
fCount = fCount + 1
# G
gainArray{gCount} = test(Fn, Ln, Q)
gCount = gCount + 1
end
plot(frequencyArray, gainArray);
结果,我收到有关数组格式的错误。
>> plot(frequencyArray, gainArray);
error: invalid value for array property "xdata"
error: __go_line__: unable to create graphics handle
error: called from
__plt__>__plt2vv__ at line 495 column 10
__plt__>__plt2__ at line 242 column 14
__plt__ at line 107 column 18
plot at line 223 column 10
除了错误之外,我相信这些任务以更正确的方式解决,但我不太明白要寻找什么。
问题:
- 我是否选择了正确的方法来解决问题?还有更优雅的方法吗?
- 我该如何解决这个错误?
谢谢!