plot - 八度不绘制函数
问题描述
我正在准备一张结合蛋白行为的图表。
x = linspace(0,1,101)
y = ( x.*2.2*(10^-4))/(( x.+6.25*(10^-2))*(x.+2.2*(10^-2)))
plot(x,y)
应该产生钟形曲线(也许)或曲线,但我得到一个线性图。我已经检查了其他软件并得出了该功能的曲线。请问有什么帮助吗?
解决方案
怎么了
您想使用./
数组除法,而不是/
矩阵除法。
如何调试这个
首先,在此处设置一些空格,以便于阅读。并添加分号来抑制大输出。
x = linspace(0, 1, 101);
y = (x.*2.2*(10^-4)) / ( ( x.+6.25*(10^-2)) * (x.+2.2*(10^-2)) );
plot(x, y)
然后将其粘贴在一个函数中以便于调试:
function my_plot_of_whatever
x = linspace(0, 1, 101);
y = (x.*2.2*(10^-4)) / ( ( x.+6.25*(10^-2)) * (x.+2.2*(10^-2)) );
plot(x, y)
现在试试:
>> my_plot_of_whatever
error: my_plot_of_whatever: operator *: nonconformant arguments (op1 is 1x101, op2 is 1x101)
error: called from
my_plot_of_whatever at line 3 column 3
当您收到关于*
or的此类投诉/
时,通常意味着您正在执行矩阵运算,而您确实想要逐元素“数组”运算.*
and ./
。修复它并重试:
>> my_plot_of_whatever
>>
那么这里发生了什么?让我们使用调试器!
>> dbstop in my_plot_of_whatever at 4
ans = 4
>> my_plot_of_whatever
stopped in /Users/janke/Documents/octave/my_plot_of_whatever.m at line 4
4: plot(x, y)
debug> whos
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
x 1x101 808 double
y 1x1 8 double
啊哈。你y
是标量,所以它对每个 X 值使用相同的 Y 值。那是因为/
当你真的想要./
数组除法时,你正在使用矩阵除法。修复:
function my_plot_of_whatever
x = linspace(0, 1, 101);
y = (x.*2.2*(10^-4)) ./ ( ( x.+6.25*(10^-2)) .* (x.+2.2*(10^-2)) );
plot(x, y)
答对了。
推荐阅读
- javascript - 反应 js useState 钩子。单击复选框时如何使用其中的数组更新json对象的状态
- azure - Azure 数据工厂管道上的 SSIS 项目部署,包括 SSH.NET 等第三方库
- python - 在 tkinter 中添加文本时防止调整按钮大小
- rest - 如何通过rest调用或程序设置apache nifi进程属性
- google-app-engine - 谷歌应用引擎错误报告不起作用
- r - R Shiny ggplot2 折线图在使用“key”属性和 facet_grid 时不会显示线条
- vue.js - 仅在满足条件时才使用插槽的后备内容
- python - 无法在 AWS EMR 上下载 nltk 语料库,对已关闭文件进行 I/O 操作
- reactjs - 使用 React 在 Front 调用 API 时出错
- amazon-web-services - 使用 AWS CLI 将现有资源导入 CloudFormation