problem in creating function file using ode45
古いコメントを表示
I am trying to solve a second order coupled ode using ode45, however I am facing issues in making it function file and providing variables as input. How to convert symbolic input to numerical in main file using ode45.
採用された回答
その他の回答 (1 件)
Are you looking for something like this? (I might have misinterpreted your equations!)
O=1;
a=pi/2;
g=9.81;
L=100;
tspan = [0 15]; % Choose Appropriate Simulation Time
ic = [0 1 0 1]; % Choose Appropriate Initial Conditions
[t,y] = ode45(@(t,y) ftotal(t,y,O,a,g,L), tspan, ic);
figure
plot(t, y)
grid
legend('y1','dy1/dt','y2','dy2/dt')
function dydt=ftotal(~,y,O, a, g, L)
y1 = y(1); v1 = y(2); y2 = y(3); v2 = y(4);
dydt = [ v1;
2*O*sin(a)*y2 - g/L;
v2;
-2*O*sin(a) - g/L*y1];
end
6 件のコメント
Susmita Panda
2023 年 3 月 11 日
編集済み: Susmita Panda
2023 年 3 月 11 日
Alan Stevens
2023 年 3 月 11 日
Hmm! You need an equation for yddot. What are your actual equations? Try uploading them exactly in mathematical notation (using an image if necessary).
Susmita Panda
2023 年 3 月 11 日
Call ode45 with the function
fun = @(t,y) [y(2); xddot; y(4); yddot]
where xddot and yddot are computed as
syms a b c d e f g h i t x y xdot ydot xddot yddot
eqn1 = (1-e)*xddot + e*yddot == -2*a*xdot - x - sin(b*t) + c*(x-y) + d*(xdot-ydot)
eqn2 = (g-h)*xddot - (i+g)*yddot == -f*(x-y)
solve([eqn1 eqn2],[xddot yddot])
Susmita Panda
2023 年 3 月 11 日
Walter Roberson
2023 年 3 月 12 日
After you get the xddot and yddot using solve(), call odeFunction to create something to pass to ode45() .
I recommend following the workflow shown in the first example to odeFunction
カテゴリ
ヘルプ センター および File Exchange で Numeric Solvers についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



