2016-03-08 136 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