0

これを聞いて申し訳ありません。これは簡単な作業だと思いますが、方法がわかりません。

数式があり、それを対y = (exp(-x) + x^2)/sqrt(pi(x)としてプロットしたいとします。yx^2

どうやってこれを行うのですか?

4

2 に答える 2

1

このような:

 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 が得られます。

ここに画像の説明を入力

于 2013-10-16T08:06:03.517 に答える
0

これが私の答えです。これはダンのものと似ていますが、根本的に異なります。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

ここに画像の説明を入力

于 2013-10-16T08:53:39.757 に答える