2017-02-16 1619 views
3

我想解決ab+tau之間的expm(A*s)積分,其中tau是時變時延。如何在Simulink中使用syms Matlab的功能塊

我在Simulink創建了一個MATLAB函數塊與tau作爲輸入,像這樣:

function y = compute_int(u, tau) 
syms s 
gamma=double(int(expm(A*s),s,a,b+tau)); 
B = [gamma; 1] 
y = B*u; 

Aab被之前定義的。這裏有一個問題,但:功能syms不SIMULINK支持。

任何想法如何處理積分?我試着用

coder.extrinsic('syms'); 

,但它不工作。

感謝您的任何建議!

+0

您可以嘗試使用'integral'將其整合爲數字形式 –

回答

1

最有用的方法:

我們不能用符號變量和匿名函數在Simulink。但是,我們可以創建出功能的其他.m文件並將其加載到Simulink中Matlab的功能塊:

myIntegral.m

function out = myIntegral(in) 
    A = [1 2 3; 4 5 6; 7 8 9]; 
    myfun = @(s) expm(A.*s); 
    out = integral(myfun,0,in,'ArrayValued',true); 
    end 

Matlab的功能塊代碼:

function y = fcn(u) 
%#codegen 
coder.extrinsic('myIntegral'); 
y = zeros(3); 
y = myIntegral(u); 

它的工作原理: enter image description here

PS順便說一句 - 我試圖

syms s1 

,並沒有錯誤在這裏,但仍然Simulink的不能使用此s1變量:

未定義的函數或變量「S1」。

+0

謝謝,它使用積分! – Betelgeuse

+0

我剛剛發現,另一種計算積分的方法可能是塊「解釋的matlab fnc」 – Betelgeuse

+0

也有[連續積分](https://www.mathworks.com/help/simulink/slref/integrator。 HTML)和[離散積分](https://www.mathworks.com/help/simulink/slref/discretetimeintegrator.html)塊。他們可能是有用的呢! –