ODE45 Why does my outcome change with the sequence of my equations?
1 view (last 30 days)
Show older comments
I am writing a code to simulate a system. It came to my attention that when I change the sequence of my differential equations, the outcomes change. Can anyone explain to me why this happens and if this is an error in my code or a mathematical phemonon? Now I do not know if my outcomes are correct.
Thank you so much for your help!
close all;
clear all;
ds = 18.32
ws = 45
br = 0.0015
bd = 0.0015
rho = 1019
g = 9.81
massvessel = ds * ws * rho
wd = 1.13
syms u1(t) u2(t) ud(t) us(t) wr(t) h(t) T Y
u1(t) == (-us * ds + wr(t) * u2(t))/wr(t);
u2(t) == (us*ds + wr(t)* u1(t))/wr(t);
ud(t) == -(u2(t)*wr(t))/wd;
as(t) = -0.5 * (((h(t))^2)*rho*g)/massvessel;
Eqns = [diff(u1(t),t) == g*(h(t)/ds) - br * (u1(t));
diff(u2(t),t) == -g * (h(t)/ds) - br * (u2(t));
diff(ud(t),t) == -g * (h(t)/ws) - bd * (ud(t));
diff(us(t),t) == as(t);
diff(wr(t),t) == us;
diff(h(t),t) == - u1(t)];
[DEsys,Subs] = odeToVectorField(Eqns);
DEfcn = matlabFunction(DEsys, 'Vars',{T,Y});
tspan = linspace(0, 400, 401);
Y0 = [0.067526; 0; 0; 0; 30; 0]+0.001;
[T, Y] = ode45(DEfcn, tspan, Y0);
Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!