# Solving DAE using daspk function

4 messages
Open this post in threaded view
|

## Solving DAE using daspk function

 hello, i would like to solve 3 DAE examples from  this paper   using daspk function. first two of them seems to work ok. the last one doesn't. here is my code # exam1 exam1x = [1.0; 0.0]; exam1xdot = [1.0; 0.0]; exam1xav = [0,1]; function f = exam1f (x, xdot, t)         f(1) = xdot(1) - t*cos(t) + x(1) - (1 + t) * x(2);         f(2) = sin(t) - x(2); endfunction # exam2 exam2x = [1.0; 1.0]; exam2xdot = [1.0; 0.0]; exam2xav = [0,1]; function f = exam2f (x, xdot, t)         f(1) = xdot(1) - x(2);         f(2) = x(2)^3.0 - x(1)^2; endfunction # exam3 exam3x = [5.0; 1.0; -1.0; 0.0]; exam3xdot = [1.0; 0.0; 0.0; 1.0]; exam3xav = [0;0;1;1]; function f = exam3f (x, xdot, t)         f(1) = xdot(1) + t*x(2) + (1.0 + t)*x(3);         f(2) = xdot(2) + t*x(1) + (1.0 + t)*x(4);         f(3) = (x(1) - x(4)) / 5.0 - cos(t^2.0/2.0);         f(4) = (x(2) - x(3)) / 5.0 - sin(t^2.0/2.0); endfunction # solve function solve (f, x0, xdot0, xav, t)         daspk_options("algebraic variables", xav);         daspk_options("initial step size", 0.1);         [x, xdot] = daspk (f, x0, xdot0, t);         printf("%10s %10s %10s\n", "t", "x0", "x1");         for i = 1:length(t)                 printf("%10.4f %10.4f %10.4f\n", t(i), x(i,1), x(i,2));         endfor endfunction # solve t = linspace(0,10,6); solve("exam1f", exam1x, exam1xdot, exam1xav, t); solve("exam2f", exam2x, exam2xdot, exam2xav, t); solve("exam3f", exam3x, exam3xdot, exam3xav, t); i'd appreciate any help / advice. thanks in advance. vit mach-zizka -- Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
Open this post in threaded view
|

## Re: Solving DAE using daspk function

 vmz, I thank you for your interesting question of the 20th, because I need to learn to solve differential-algebraic equations.  I'm not particularly familiar with daspk yet, so I don't know why your third example isn't working, but you can solve the third and fourth equations (the algebraic ones) for x(3) and x(4) by hand, and just substitute those values back into the first two equations, turning the system into a pure differential equation (please check my work to see if I got the equations correct): function f = exam4f(x, xdot, t)   f(1) = xdot(1)+t*x(2)+(1.0+t)*(x(2)-5*sin(t^2/2));   f(2) = xdot(2)+t*x(1)+(1.0+t)*5*(x(1)-5*cos(t^2/2)); endfunction Still using daspk (because it was handy), I tried this function and got a solution. The solution gets really truly enormous very quickly, so I don't know whether to believe it or not, but at least it doesn't crash. Regards, Allen -- Allen Windhorn P.E. (Mn), CEng| Senior Principal Engineer Leroy-Somer Americas | Kato Engineering, Inc. 2075 Howard Dr. West | North Mankato, MN 56003 | USA T +1 507-345-2782 | F +1 507-345-2798 [hidden email] | [hidden email]