我對此表示歉意,我相信這是一個簡單的任務,但我不知道該怎麼做。如何繪製帶定製座標軸的圖形
假設我有一個公式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
第二個方法讓你像一個陰謀
編輯:
其實我覺得你問的這個:
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)
所以我在這裏繪製一個簡單的二次曲線,但如果我將它繪製成平方它應該變成線性的。但是我仍然想讀出y = x^2而不是y = x的圖,我只是想讓它看起來像y = x。因此,如果我讀取該圖上x值爲4的y值,我將得到16,這仍然是相同的正確的原始y值。
這裏是我的答案是:它類似於丹的一個,但根本的不同。你可以計算的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
您的公式有錯誤,遺漏括號,缺少'.'s的元素方面的操作,也'PI(X)'是極不可能的,你是什麼意思。請修復這些。 – Dan