2017-02-01 40 views
-2

我想知道是否有人有任何洞察,爲什麼這兩個劇情命令產生的數量級是不同的域?而y被評估並繪製 「謹慎」MATLAB:符號工具箱繪圖與謹慎繪圖

syms t 
x1Axis = 0:.01:10; 
fun1(t) = sin(t) 
plot(sin(x1Axis)) 
hold on 
y = sin(x1Axis) 
plot(x1Axis, y) 

fun1(t)繪製 「象徵性」。我應該在第一個功能的情況下使用不同的繪圖方法嗎?

回答

2

不,你沒有正確地繪製符號函數。

在您的代碼中,指令plot(sin(x1Axis))不是符號圖,而是正弦值與每個值的索引的數字圖。

plot documentation page

plot(Y)創建在Y數據的2-d線圖對的 每個值的索引。

  • 如果Y是矢量,則x軸刻度範圍是1length(Y)

要繪製符號功能使用fplot

下面的例子將讓你看到,無論是符號和數字地塊是相同的:

xmin = 0; 
xmax = 10; 

% Symbolic Plot. 
syms t 
fun1(t) = sin(t); 
fplot(fun1, [xmin xmax], '-r'); 

hold on; 

% Numeric Plot. 
x = xmin:.01:xmax; 
y = sin(x); 
plot(x, y, '--g'); 

% Add legend. 
legend('Symbolic Plot', 'Numeric Plot', 'Location', 'north'); 

這是結果:

Sine: Symbolic and Numeric plot