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

采纳的回答

Walter Roberson
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 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by