Create Symbolic functions with existing function file

2 ビュー (過去 30 日間)
Penglin Cai
Penglin Cai 2020 年 6 月 17 日
コメント済み: Walter Roberson 2020 年 6 月 18 日
Dear all.
I have created a function to represent a dynamical system with variables z=[x1,y1,x2,y2,...xn,yn] as following:
Alpha, beta, gamma and S are constants. Now l have a new script and l want to call this function in my new script as a symbolic function but MATLAB reterened me error said that ''undefined z''. Could you tell me that how l can create a symbolic function using the function l have. Thank you very much!

採用された回答

David Hill
David Hill 2020 年 6 月 17 日
It should work, you just need to pass a symbolic z to the function. It would help in the future if you created code that we could copy and paste.
syms x1 y1 x2 y2 x3 y3 x4 y4;
z=[x1,y1,x2,y2,x3,y3,x4,y4];
f=coupledOscillatorsFun(z,1,2,3,4);
  2 件のコメント
Penglin Cai
Penglin Cai 2020 年 6 月 18 日
Thank you sir. But what if i want to do for n variables (very large z vector)?
Walter Roberson
Walter Roberson 2020 年 6 月 18 日
n = 4;
x = sym('x', [1 n]);
y = sym('y', [1 n]);
z = [x; y];
z = z(:);
f = coupledOscillatorsFun(z, 1, 2, 3, 4);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by