Handling with long function in ode45
5 ビュー (過去 30 日間)
古いコメントを表示
Hi.
I have a problem with operating a long function in ode45:
[t,y] = ode45(@(t,y) [(V^2*A/((p_r(1)*y(1)+p_r(2))*1e-6)-(0.1558*y(1) +89.33)*Ac*(y(1)-Ta))/(m*(p_c(1)*y(1)^2+p_c(2)*y(1)+p_c(3))); -((V^2*A/((p_r(1)*y(1)+p_r(2))*1e-6)-(0.1558*y(1) +89.33)*Ac*(y(1)-Ta))/(m*(p_c(1)*y(1)^2+p_c(2)*y(1)+p_c(3))))*(0.5*ksiM*aA*omega*sin(aA*(y(1)-As)+bA*y(2))*(1/(1+exp(-s*(y(1)-As)))-1/(1+exp(-s*(y(1)-Af))))-theta)/(1+0.5*ksiM*bA*omega*sin(aA*(y(1)-As)+bA*y(2))*(1/(1+exp(-s*(y(1)-As)))-1/(1+exp(-s*(y(1)-Af)))))] , [0 3], [20;0]);
As you can see the function is very long, in fact it is even a system of two. Would it be possible to write a piece of this function, for example:
sin(aA*(y(1)-As)+bA*y(2))
as simple expression, let's say:
f
and use this short expression inside ode45 instead of much longer sine? This would make it much easier for me to operate the function.
Kind regards
Olaf
0 件のコメント
採用された回答
Walter Roberson
2020 年 3 月 10 日
Yes, you can use anonymous functions.
You should consider using a real function file for the expressions as you can use as many variables as you like to make the code clearer or more efficient.
If you have the symbolic toolbox then you can even use matlabFunction to write optimized code to a file.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!