Why do I receive this error msg when solving a simple DAE with odefunction?
1 view (last 30 days)
Show older comments
When I solve this simple DAE with three variables y1(t), y2(t), y3(t),
y1' = y2' + y1;
y2' = y1;
y3 = y1 + y2;
y1(0) = 1.0;
y2(0) = 0.5;
y3(0) = 1.5;
syms y1(t) y2(t) y3(t)
eqs = [diff(y1(t),t) == diff(y2(t),t) + y1(t),...
diff(y2(t),t) == y1(t),...
y3(t) == y1(t) + y2(t)];
vars = [y1(t) y2(t) y3(t)];
initConditions = [1 0.5 1.5];
[M,F] = massMatrixForm(eqs,vars);
M = odeFunction(M,vars);
F = odeFunction(F,vars);
opt = odeset('mass',M);
ode15s(F, [0 1], initConditions, opt)
I receive this error msg:
Need a better guess y0 for consistent initial conditions.
This DAE is simple, if subs y2' = y1 into first equation, then y1' = 2y1. With y1(0) = 1, y2(0) = 0.5, can solve y1 = e^2t and y2 = e^2t/2. And y3(0) = y1(0)+y2(0)=1.5. What's wrong with my guess on initial condition, most likely for y3?
0 Comments
Answers (1)
Harshitha Kallam
on 15 Jun 2021
Yes, the most likely reason for error is the initial value of y3 that is resulting in inconsistency.
A possible workaround can be to first solve for y1(t), y2(t) and then calculate y3(t) which is a summation of those two. Alternatively, the below modification can be done.
eqs = [diff(y1(t),t) == diff(y2(t),t) + y1(t),...
diff(y2(t),t) == y1(t),...
diff(y3(t),t) == diff(y1(t) + y2(t),t)]; %changing the last eqn
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!