2016-03-08 114 views
0

目前我正在試圖通過繪製f(x) = r*x*(1-x)(其中r =3)和y=x在同一張圖:繪製邏輯圖

syms r x; 
f = symfun(r*x*(1-x), x) 
r = 3 
plot(f,x) 
plot(x,x) 

但我的代碼保存導致錯誤:

Error using plot 
A numeric or double convertible argument is expected 

請有人可以幫助指出我出錯的地方嗎?

回答

4

錯誤很明顯:將一個數字參數傳遞給plot。你給它一個象徵性的功能。只需使用

r = 3; 
x = 0:0.1:10; %// set some x 
f = (r.*x.*(1-x)); %// dots make the multiplication element-wise 
figure; %// opens figure 
hold on %// plots multiple things in one figure 
plot(f,x) 
plot(x,x,'r') %// produces a red plot 

enter image description here