2013-05-12 44 views
1

一個複雜的函數在Matlab中的命令窗口我得到幾個公式看起來像:實現在Simulink

Tc1 = (- 2*J2*cos(t3)*sin(t1)*sin(t3)*n^2 + 2*J2*w3*sin(t3)*n)/cos(t2) - d2 + cos(t2)*(J2*cos(t3)*sin(t1)*sin(t3)*n^2 + J2*v3*sin(t1)) + J1*w1*w3 + J2*w1*w3 - J3*w1*w3 + J2*v2*cos(t1) + J2*n^2*cos(t1)*tan(t2) - J2*w2^2*cos(t1)*tan(t2) + 2*J2*w3^2*cos(t1)*tan(t2) + J2*w2^2*cos(t1)^3*tan(t2) - J2*w3^2*cos(t1)^3*tan(t2) - 2*J2*n*w2*cos(t3)*tan(t2) + 2*J2*w2*w3*sin(t1)*tan(t2) - J2*n^2*cos(t1)*cos(t3)^2*tan(t2) + 2*J2*n*w2*cos(t1)^2*cos(t3)*tan(t2) - 2*J2*w2*w3*cos(t1)^2*sin(t1)*tan(t2) - 2*J2*n*w3*cos(t1)*cos(t3)*sin(t1)*tan(t2)   

在Simulink中我使用從和Goto塊爲所有參數(Tc1的,J1,J2,J3,T1 ,t2,t3等)。

現在我想知道最簡單的方法是在Simulink中實現這些長公式以進行模擬。通常情況下,我只是用Simulink中的所有模塊重建方程,但這次結束的方程要長得多。有任何想法嗎?

回答

2
  1. 第一種方式是使用Fcn塊從用戶定義的函數和只寫你函數在一行中,並使用輸入的像u(1)u(2),....

Fcn塊應用指定的數學表達式的輸入。表達式可以包括以下一個或多個組件:

  • u - 塊的輸入。如果u是矢量,則u(i)表示 矢量的第i個元素; u(1)u單獨代表 第一個元素。
  • 數字常量。
  • 算術運算符(+-*/^)。
  • 關係運算符(==>!=<>=<=) - 的 表達式返回1如果該關係是真實的;否則,返回 0
  • 邏輯運算符(&&||!) - 如果關係爲真,則表達式返回1 ;否則,它返回0
  • 括號。
  • 數學函數 - absacosasinatanatan2ceilcoscoshexpfabsfloorhypotlnloglog10powpowerremsgnsinsinhsqrttan, 和tanh

檢查此link


  • 的第二種方法是使用從用戶定義的函數Matlab Function和寫所有你在嵌入式m-file具有的功能。然後將所有輸入和輸出連接到它。
  • 檢查這個link

    +0

    我已經實現了第二種方法,它工作得很好,非常感謝! – Pietair 2013-05-14 13:52:09