如何绘制 (x- 1)/ (y 2)^ 1.8?
How to plot (x-1)/(y+2)^1.8?
我尝试使用 surf()
方法在八度音程中绘制方程 (x-1)/(y+2)^1.8
。但是图表是另外一回事。
这是我的代码:
p = linspace(1,50, 100);
t = linspace(1,48,100);
ans = zeros(length(p), length(t));
ans = compute_z(p, t, ans);
figure;
surf(p, t, ans');
尝试使用辅助函数 compute_z
计算 z = (x-1)/(y+2)^1.8
function [ans] = compute_z(ans, p, t)
for i = 1:length(p)
for j = 1:length(t)
ans(i,j) = (p(i) - 1) / (t(j)+2)^1.8;
end
end
我正在尝试生成 this graph.
您的问题是您按顺序将 compute_z
输入定义为 ans
、p
和 t
。但是,您可以按 p
、t
和 ans
的顺序调用该函数。你看到问题了吗?
ans
不是函数的输入,只是输出,因此无需将其列为输入。此外,不要调用您的变量 ans
,它是 MATLAB 在未指定输出变量名称时使用的默认变量名称,因此很可能被覆盖。
这是我的建议:
p = linspace(1,50, 100);
t = linspace(1,48,100);
z = zeros(length(p), length(t));
z = compute_z(p, t);
figure;
surf(p, t, z');
与compute_z
定义如下:
function z = compute_z(p, t)
for i = 1:length(p)
for j = 1:length(t)
z(i,j) = (p(i) - 1) / (t(j)+2)^1.8;
end
end
不需要你的compute_z-method
,因为你可以meshgrid
和矢量化。
p = linspace(1,50, 100);
t = linspace(1,48,100);
[P, T] = meshgrid(p,t); Z = (P-1) ./ (T+2).^1.8;
figure;
surf(P, T, Z);
(在 Matlab 中测试过,但也应该在 Octave 中工作)
我尝试使用 surf()
方法在八度音程中绘制方程 (x-1)/(y+2)^1.8
。但是图表是另外一回事。
这是我的代码:
p = linspace(1,50, 100);
t = linspace(1,48,100);
ans = zeros(length(p), length(t));
ans = compute_z(p, t, ans);
figure;
surf(p, t, ans');
尝试使用辅助函数 compute_z
z = (x-1)/(y+2)^1.8
function [ans] = compute_z(ans, p, t)
for i = 1:length(p)
for j = 1:length(t)
ans(i,j) = (p(i) - 1) / (t(j)+2)^1.8;
end
end
我正在尝试生成 this graph.
您的问题是您按顺序将 compute_z
输入定义为 ans
、p
和 t
。但是,您可以按 p
、t
和 ans
的顺序调用该函数。你看到问题了吗?
ans
不是函数的输入,只是输出,因此无需将其列为输入。此外,不要调用您的变量 ans
,它是 MATLAB 在未指定输出变量名称时使用的默认变量名称,因此很可能被覆盖。
这是我的建议:
p = linspace(1,50, 100);
t = linspace(1,48,100);
z = zeros(length(p), length(t));
z = compute_z(p, t);
figure;
surf(p, t, z');
与compute_z
定义如下:
function z = compute_z(p, t)
for i = 1:length(p)
for j = 1:length(t)
z(i,j) = (p(i) - 1) / (t(j)+2)^1.8;
end
end
不需要你的compute_z-method
,因为你可以meshgrid
和矢量化。
p = linspace(1,50, 100);
t = linspace(1,48,100);
[P, T] = meshgrid(p,t); Z = (P-1) ./ (T+2).^1.8;
figure;
surf(P, T, Z);
(在 Matlab 中测试过,但也应该在 Octave 中工作)