これを聞いて申し訳ありません。これは簡単な作業だと思いますが、方法がわかりません。
数式があり、それを対y = (exp(-x) + x^2)/sqrt(pi(x)
としてプロットしたいとします。y
x^2
どうやってこれを行うのですか?
これを聞いて申し訳ありません。これは簡単な作業だと思いますが、方法がわかりません。
数式があり、それを対y = (exp(-x) + x^2)/sqrt(pi(x)
としてプロットしたいとします。y
x^2
どうやってこれを行うのですか?
このような:
X = 0:0.1:5; %// Get the x values
x = X.^2; %// Square them
%// Your formula had errors, I fixed them but I could have misinterpreted here, please check
y = (exp(-x) + x.^2)./sqrt(pi*x); %// Calculate y at intervals based on the squared x. This is still y = f(x), I'm just calculating it at the points at which I want to plot it.
plot(x,y) %//Plot against the square X.
この時点で、これは通常にプロットしたのと変わりません。あなたが望むのは、目盛りが の値で上がるようにすることですX.^2
。これは、y 値を変更したり、関数を歪めたりしません。視覚的にどのように見えるかを変更するだけです。対数スケールに対するプロットに似ています。
set(gca, 'XTick', X.^2) %//Set the tickmarks to be squared
2番目の方法は、次のようなプロットを提供します
編集:
実際、あなたはこれを求めていたと思います:
x = 0:0.1:5;
y = x.^2; %// Put your function in here, I'm using a simple quadratic for illustrative purposes.
plot(x.^2,y) %//Plot against the square X. Now your y values a f(x^2) which is wrong, but we'll fix that later
set(gca, 'XTick', (0:0.5:5).^2) %//Set the tickmarks to be a nonlinear intervals
set(gca, 'XTickLabel', 0:0.5:5) %//Cahnge the labels to be the original x values, now accroding to the plot y = f(x) again but has the shape of f(x^2)
ここでは単純な 2 次曲線をプロットしていますが、2 乗した x に対してプロットすると線形になるはずです。ただし、y=x ではなく y=x^2 であるというグラフを読み上げたいのですが、y=x のように見せたいだけです。したがって、そのグラフの x 値 4 の y 値を読み取ると、元の y 値と同じ正しい 16 が得られます。
これが私の答えです。これはダンのものと似ていますが、根本的に異なります。y
の関数としての値を計算できますが、 の関数x
としてプロットしますx^2
。これは、私の理解が正しければ、OP が求めていたものです。
x = 0:0.1:5; %// Get the x values
x_squared = x.^2; %// Square them
%// Your formula had errors, I fixed them but I could have misinterpreted here, please check
y = (exp(-x) + x.^2)./sqrt(pi*x); %// Calculate y based on x, not the square of x
plot(x_squared,y) %//Plot against the square of x
ダンが述べたように、目盛りはいつでも変更できます。
x_ticks = (0:0.5:5).^2; % coarser vector to avoid excessive number of ticks
set(gca, 'XTick', x_ticks) %//Set the tickmarks to be squared