2014-03-12 225 views
1

我對本人已寫入其內插的實驗值,也是曲線,該曲線擬合近似的內插數據Matlab的:錯誤矩陣尺寸

在i計算插值我是一個功能的改變的形狀分析建模獲得矩陣失配誤差,請您審查,並讓我知道我的我的錯誤

function [c_i,c_f,c_e] = M_shape_analysis(t,S,a1,a2,td,tmax,alpha,Be,p,q,r,k_el,k1,k2,k3) 
%Modified Shape_analysis and estimating K3 
% Interpolation of measured Data points 



c_i = zeros(size(t)); 

ind = (t > td) & (t < tmax); 
c_i(ind) = S *(1 - exp(-alpha*t(ind))); 
%c_t(ind)= (A_max*K_1*(t(ind)/(k2+k3)-(td*(k2+k3)/(k2+k3).^2)-(td/(k2+k3) -(td*(k2+k3)/(k2+k3).^2))*exp(-(k2+k3)*(t(ind)-td)))+(0.5*K_2*(t(ind)-td).^2)); 


ind = (t >= tmax); 

a3 =(S *(1 - exp(-alpha*t(ind))) -(a1+a2)); 
c_i(ind) = a1*exp(-p * (t(ind) - tmax))+ a2*exp(-q * (t(ind) - tmax)) + a3*exp(-r * (t(ind) - tmax)); 
%c_t(ind) =((K_1*(A/(k2+k3-B))*(exp(B*(t(ind)-tmax))- exp(-(k2+k3)*(t(ind)-tmax)))+(K_2*(A/B)*(1+exp(B*(t(ind)-tmax)))))); 


%ft = fittype('Input_function(t, a1, a2, a3, b1, b2, b3, td, tmax)', 'independent', 't'); 

%fo = fit(t, c, ft,'StartPoint', [20000, 20000, 20000, 0.01, 0.01, 0.01, 10, 30],'Lower', [0, 0, 0, 0, 0, 0, 0, 0]); 


%plot(t,c_t); 
hold all; 
subplot(2, 2, 2); 
plot(t, c_i,'x'); 
axis([0 50 -2000 80000]); 
xlabel time ; 
ylabel concentration ; 



%-------------------------------------------------------------------------------------------------------------------------- 
    % Fitting the measured Data 

ind = (t > td) & (t < tmax); 

c_f(ind)= conv(((t(ind) - td) ./ (tmax - td) * (a1 + a2 + a3)),(k1*exp(-(k2+k3)*t(ind)+((k1*k3)/(k2+k3-k_el)))),'same'); 


ind = (t >= tmax); 

c_f(ind) = conv((a1 * exp(-b1 * (t(ind) - tmax))+ a2 * exp(-b2 * (t(ind) - tmax))) + a3 * exp(-b3 * (t(ind) - tmax)),(k1*exp(-(k2+k3)*t(ind)+((k1*k3)/(k2+k3-k_el)))),'same'); 


hold all; 
subplot(2, 2,4); 
plot(t, c_f); 
axis([0 50 -2000 80000]); 
xlabel time ; 
ylabel concentration ; 

%plot(ts, Input_function(ts, fo.a1, fo.a2, fo.a3, fo.b1, fo.b2, fo.b3, fo.td, fo.tmax)); 

%-------------------------------------------------------------------------------------------------------------------------- 
    % Plotting K3 Estimate : Fitted curve 

    DV_free= k1/(k2+k3); 

    ind = (t >= tmax); 
    c_e(ind) = DV_free* exp(-Be*t(ind)); 

subplot(2, 2, 6); 
plot(t, c_e); 

axis([0 50 -2000 80000]); 
xlabel time ; 
ylabel concentration ; 



end 

下面是我獲得

Error using * 
Inner matrix dimensions must agree. 

Error in M_shape_analysis (line 17) 
c_i(ind) = a1*exp(-p * (t(ind) - tmax))+ a2*exp(-q * (t(ind) - tmax)) + a3*exp(-r * 
(t(ind) - tmax)); 
錯誤

請讓我知道我在我的模型中的錯誤位置

+0

上一行中a3的定義將在length(ind)> 1時產生一個數組。所以'a3 * exp(...)'會給你一個錯誤。使用'。*'代替 –

+0

@ R.Schifini非常感謝,效果很好 – DevanDev

回答

0

我不能指出確切的錯誤在哪裏,因爲我不知道輸入參數的尺寸。該錯誤是由於您使用的是*操作時,無論是事實:

  1. 你要相乘的兩個矩陣的尺寸時執行矩陣乘法不同意。例如,一個必須是mxn,另一個必須是nxk矩陣。我假設你知道這一點。

  2. 你想執行元素乘法而不是矩陣乘法。如果是這種情況,那麼您必須使用.*運算符。如果要將標量乘以矢量(或矩陣),則可以使用任一運算符。

我相信點沒有。 2是錯誤的原因。

閱讀timesmtimes即(.* vs *)。