[英]How do I plot this simple thing correctly in Octave?
I am a student trying to learn how to use Octave and I need help with plotting this thing right here the function I want to plot我是一名试图学习如何使用 Octave 的学生,我需要帮助在这里绘制这个东西function 我想要 plot
The code looks like this:代码如下所示:
x2 = 0:0.1:50;
y2 = power((1+(2.*x2/(exp(0.5.*x2)+(x2.^2)))), 0.5);
plot(x2, y2, '-b');
It feels like it should have plotted without problems but the plot in the figure appears to be completely empty, and I cannot wrap my head around why this might happen.感觉它应该没有问题地绘制,但图中的 plot 似乎完全是空的,我无法理解为什么会发生这种情况。 Would love to know what am I doing wrong很想知道我做错了什么
If you inspect the value of y2
(simply type y2
and press enter) then you find that y2
is a single number rather than a vector.如果您检查y2
的值(只需输入y2
并按回车键),您会发现y2
是单个数字而不是向量。
To find out out why y2
is a single number we type in the calculation power((1+(2.*x2/(exp(0.5.*x2)+(x2.^2)))), 0.5)
and remove the outer functions/operators step by step.要找出为什么y2
是单个数字,我们输入计算power((1+(2.*x2/(exp(0.5.*x2)+(x2.^2)))), 0.5)
并删除外部函数/运算符一步一步。 Once the result is a vector we know that the last thing removed ruined the result.一旦结果是一个向量,我们就知道最后删除的东西破坏了结果。
In your case /
turns out to be the culprit.在你的情况下/
原来是罪魁祸首。
From Octave, Arithmetic Ops (emphasis mine):来自Octave,算术运算(重点是我的):
x / y
Right division.正确的划分。 This is conceptually equivalent to the expression(inv (y') * x')'
but it is computed without forming the inverse ofy'
.这在概念上等价于表达式(inv (y') * x')'
但它的计算没有形成y'
的倒数。 If the system is not square , or if the coefficient matrix is singular, a minimum norm solution is computed .如果系统不是方的,或者系数矩阵是奇异的,则计算最小范数解。
x./ y
Element-by-element right division.逐元素右除。
Therefore, replace /
by ./
.因此,将/
替换为./
。
x2 = 0:0.1:50;
y2 = power(1 + 2 .* x2 ./ (exp(0.5 .* x2) + (x2 .^ 2)), 0.5);
plot(x2, y2, '-b');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.