x = 0:1:5; % define x array
y = exp(x)+x.^4+2*x.^2-x+3; % define y array
dx = diff(x); % 1 1 1 1 1 dx has one number less than x
dy = diff(y); % -5 -1 -3 -4 -2
slope = dy./dx
z=exp(x)+4*x.^3 +4*x-1
plot(x,slope,'*',x,z)
'Error using plot Vectors must be the same length.'
“使用图向量的错误必须是相同的长度。”
Been stuck on this for a while, I am not sure what to do. ive seen the other responses to the same error but can not understand the code. It seems its the colon : that might help but i am not sure how to use it.
我被困在这里一段时间了,我不知道该怎么办。我看到了对相同错误的其他响应,但无法理解代码。它似乎是冒号:可能会有帮助,但我不知道如何使用它。
Any help would be appreciated!
如有任何帮助,我们将不胜感激!
1 个解决方案
#1
1
Since slope
is computed from two consecutive values, I suggest you take the average betwen consecutive points as the x
-axis values for ´slope`:
从两个连续值斜率计算之后,我建议你以平均前后连续点为轴´斜率值”:
plot((x(1:end-1)+x(2:end))/2,slope, '*',x,z)
#1
1
Since slope
is computed from two consecutive values, I suggest you take the average betwen consecutive points as the x
-axis values for ´slope`:
从两个连续值斜率计算之后,我建议你以平均前后连续点为轴´斜率值”:
plot((x(1:end-1)+x(2:end))/2,slope, '*',x,z)