2013-08-22 64 views
-1

策划我想T0变化到2000100间隔{共20个图形都在同}MATLAB for循环与变参数

给一个绘制该

f(x)=3*(1-x)+7*x+8.314*T((1-x)*(lnx)+x*(lnx))+20*x(1-x) 

涉及循环和绘图功能的非常基本的代码。 PS:我在MATLAB

+0

你的意思是20点,而不是20个图? –

回答

0
[email protected](x,T) 3*(1-x)+7*x+8.314*T*((1-x).*log(x)+x.*log(x))+20*x.*(1-x); 
T=0:100:2000; 
x=linspace(0,10,100); 
for i=1:length(T) 
    plot(x,f(x,T(i))); 
    hold on; 
end 
1

欢迎Matlab的一个beginer。 :)下面是我们如何做到这一点没有循环:

% Define your function in terms of x and T 
% Note that we use .* instead of * - this does a pairwise multiply 
% instead of a matrix or vector multiply 
f = @(x,T) 3*(1-x)+7*x+8.314*T.*((1-x).*log(x)+x.*log(x))+20*x.*(1-x); 

% Set your domain 
x = linspace(0, 10, 101); 
T = (0:100:2000); 

% Compute your function for all values of x and T 
tmp = bsxfun(f, x, T'); 

% Plot your output, all at the same time 
plot(x, tmp)