ODE45 solver problem outcome

3 visualizaciones (últimos 30 días)
Iris Heemskerk
Iris Heemskerk el 17 de Abr. de 2020
Comentada: Star Strider el 19 de Abr. de 2020
I have 5 differential equations and a couple of extra equations that I want to solve for 5 variables.
The problem is that if you look at the graph you see that the outcomes do not match. dh/dt should be -u1(t) but that is not the case in the graphs. I do not know where it goes wrong in my code.
If I put the equations for u1(t), u2(t) and ud(t) in the Eqns the same results are obtained which seems strange to me. How do I write the code such that all equations are true?
clear all;
ds = 18.32
ws = 45
br = 0.0015
bd = 0.0015
rho = 1019
g = 9.81
us = 0.06
massvessel = ds * ws * rho
wd = 1.13
syms u1(t) u2(t) ud(t) h(t) wr(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;
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(h(t),t) == - u1(t);
diff(wr(t),t) == -us];
[DEsys,Subs] = odeToVectorField(Eqns);
DEfcn = matlabFunction(DEsys, 'Vars',{T,Y});
tspan = linspace(0, 200, 251);
Y0 = [0; 0; 0; 0; 30]+0.001;
[T, Y] = ode45(DEfcn, tspan, Y0);
  2 comentarios
darova
darova el 17 de Abr. de 2020
Here is the mistake
You are not assigning equation to variable. Use '=' sign once
Iris Heemskerk
Iris Heemskerk el 17 de Abr. de 2020
@darova Thank you so much for your help!
If I change this however, the following error appears:
Error using mupadengine/feval_internal (line 172)
Unable to convert the initial value problem to an equivalent dynamical system.
Either the differential equations cannot be solved for the highest derivatives or
inappropriate initial conditions were specified.
Error in odeToVectorField>mupadOdeToVectorField (line 171)
T = feval_internal(symengine,'symobj::odeToVectorField',sys,x,stringInput);
Error in odeToVectorField (line 119)
sol = mupadOdeToVectorField(varargin);
Error in simulatieexp1nonlinear (line 33)
[DEsys,Subs] = odeToVectorField(Eqns);

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 17 de Abr. de 2020
The ‘==’ are correct here. They are symbolic equations, not logical operations. Otherwise, I would agree.
Also, your code works correctly. The integrated value ‘h(t)’ will appear different from ‘-u1(t)’ because it is integrated. If you plot ‘u1(t)’ (integrated as ‘Y(:,2)’) against the negative of the derivative of ‘h(t)’:
figure
plot(T,Y(:,2), '-b', T,-gradient(Y(:,4),tspan(2)), '--r')
grid
(with the derivative calculated by the gradient function), they are almost exactly the same.
.
  16 comentarios
Iris Heemskerk
Iris Heemskerk el 19 de Abr. de 2020
Okay, that is what I thought the problem was. However if you plot this code and you look at the graph of ud(t).
The outcome of the solver (ud) does not agree with ud = wr * u2/wd (figure 2 in the code).
close all;
clear all;
ds = 18.32
ws = 45
br = 0.0015
bd = 0.0015
rho = 1019
g = 9.81
us = 0.06
massvessel = ds * ws * rho
wd = 1.13
syms u1(t) u2(t) ud(t) h(t) wr(t) T Y
Eqns = [diff(u1(t),t) == g*(h(t)/ds) - br * ((-us * ds + wr(t) * u2(t))/wr(t));
diff(u2(t),t) == -g * (h(t)/ds) - br * ((us*ds + wr(t)* u1(t))/wr(t));
diff(ud(t),t) == -g * (h(t)/ws) - bd * ((u2(t)*wr(t))/wd);
diff(h(t),t) == - u1(t);
diff(wr(t),t) == -us];
[DEsys,Subs] = odeToVectorField(Eqns);
DEfcn = matlabFunction(DEsys, 'Vars',{T,Y});
tspan = linspace(0, 400, 401);
Y0 = [0; 0.0675; 1.41; 0; 30]+0.001;
[T, Y] = ode45(DEfcn, tspan, Y0);
figure
for k = 1:size(Y,2)
subplot(size(Y,2),1,k)
plot(T, Y(:,k))
grid
legend(string(Subs(k)))
end
figure
plot(T, Y(:,3))
hold on
plot(T, Y(:,1).*Y(:,5)./wd)
legend('ud', 'ud = u2 * wr/wd')
Star Strider
Star Strider el 19 de Abr. de 2020
It will not agree, because the value of that is plotted is the integrated value of as coded in ‘Eqns’.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Applications en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by