2012-10-12 28 views
0

我有計算功能如何在Matlab中做多元函數的基本繪圖?

(c^(2n) - 1)/(c^(2n) + 1) as n = 1,2,3的限制...趨近於無窮

功能的行爲將取決於參數c,我想說明是繪出第100 (或大約)的值,對於c的不同值 - 例如三個圖,一個用於c = 1,一個用於-1 < c < 1,另一個用於c > 1,如果可能的話,全部在一個「圖片」內。

什麼是最好的方法來解決這個問題在MATLAB中?

+0

這取決於你已經知道多少關於MATLAB語法。如果你可以在MATLAB中編寫這個表達式並且知道一個簡單的'for'循環的語法,我想你可以提出一個更具體的問題。如果不是的話,我想你應該和你的Prof/TA談談MATLAB入門基礎知識。 –

+0

最好的方法是嘗試一些東西。你通過做,而不是由別人給你答案學習。如果你完全不知道該怎麼做,那麼你就沒有打算通過MATLAB的真實基礎。那麼你有什麼嘗試? – 2012-10-12 22:51:46

回答

2

您需要使用內聯函數,保留所有內容和圖例。下面是一個簡單的例子

n=1:100; 
f = @(c) (c.^(2.*n) - 1)./(c.^(2.*n) + 1); 
hold all; 
plot(n,f(0.7),'.-'); 
plot(n,f(0.9),'.-'); 
plot(n,f(0.95),'.-'); 
plot(n,f(1),'.-'); 
plot(n,f(1.05),'.-'); 
plot(n,f(1.3),'.-'); 
plot(n,f(1.1),'.-'); 
legend('c=0.7','c=0.9','c=0.95','c=1.0','c=1.05','c=1.3','c=1.1'); 

這樣做的輸出看起來像這樣 enter image description here

2

我會做這樣的事情:

% Clean up, this isn't necessary if you're throwing this in a function 
% and not a script. 
close all 
clear all 
clc 

% Define your function 
f = @(c,n)((c^(2*n) - 1)/(c^(2*n) + 1)); 

% An array containing the values of c you want to use 
C = [0.5, 1, 1.5, 2]; 

% N will contain 500 points, equally spaced between 1 and 20. 
% (Modify these arguments as necessary) 
N = linspace(1,20,500); 

% Initialize an output matrix 
Y = zeros(length(N), length(C)); 
for i = [1:length(C)] 
    c = C(i); 

    for j = [1:length(N)] 
     n = N(j); 

     % Compute value of function 
     y = f(c,n); 

     % Store it 
     Y(j,i) = y; 
    end%for 
end%for 

% Plot it 
plot(N,Y); 

% Generate Legend 
lt = cell(1,length(C)); 
for i = [1:length(C)] 
    lt{i} = sprintf('C = %s', num2str(C(i))); 
end%for 
legend(lt); 

你可以通過修改功能f接受並返回向量優化,但是,這個明確的版本可能顯示是怎麼回事更好。