help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Solving DAE using daspk function


From: vmz
Subject: Solving DAE using daspk function
Date: Wed, 20 Nov 2019 10:53:29 -0600 (CST)

hello,

i would like to solve 3 DAE examples from  this paper
<https://pdfs.semanticscholar.org/c750/77a37def9367e373a50e1570d69ee97fdc8f.pdf>
  
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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]