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일

0 개 추천

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개)

카테고리

제품

릴리스

R2019b

질문:

2020년 3월 10일

답변:

2020년 3월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by