Is there a way to solve differential equation $dot x = f(x,u)$ with linear algebra?
$begingroup$
I'm going to solve a ODE system on the form:
$$dot x(t) = f(x(t),u(t))$$
Where an example of the system migth look like:
$$(dot x_1(t) ,dot x_2(t) ,dot x_3(t))= a x_1(t) + b x_2 (t) + c x_3 (t) + d u(t) e x_2 (t) + f u(t) g x_1(t) + h sin(x_3(t))$$
The parameters $a,b,c,d,e,f,g,h$ are known and $x_1,x_2,x_3,dot x_1,dot x_2,dot x_3$ are known for $t = 0$ and $u$ are known $forall t$. Also $u$ is constant $forall t$.
So is there a way to to find $x_1,x_2,x_3$ by using linear algebra? I just got started with Armadillo and C++, then I realize that Armadillo does not have and ODE solver. But Armadillo is optimized for linear algebra.
ordinary-differential-equations simulation
$endgroup$
|
show 14 more comments
$begingroup$
I'm going to solve a ODE system on the form:
$$dot x(t) = f(x(t),u(t))$$
Where an example of the system migth look like:
$$(dot x_1(t) ,dot x_2(t) ,dot x_3(t))= a x_1(t) + b x_2 (t) + c x_3 (t) + d u(t) e x_2 (t) + f u(t) g x_1(t) + h sin(x_3(t))$$
The parameters $a,b,c,d,e,f,g,h$ are known and $x_1,x_2,x_3,dot x_1,dot x_2,dot x_3$ are known for $t = 0$ and $u$ are known $forall t$. Also $u$ is constant $forall t$.
So is there a way to to find $x_1,x_2,x_3$ by using linear algebra? I just got started with Armadillo and C++, then I realize that Armadillo does not have and ODE solver. But Armadillo is optimized for linear algebra.
ordinary-differential-equations simulation
$endgroup$
$begingroup$
The example system seems to be written incorrectly. On the left, you should have $(x_1'(t), x_2'(t), x_3'(t))$. You could implement your own ODE solver (using a method like RK4), or alternatively you could probably find a C++ library that provides an ODE solver that you can use. Here's a thread with some library suggestions: stackoverflow.com/questions/7622286/…
$endgroup$
– littleO
Dec 17 '18 at 0:12
$begingroup$
I'm used to write the x_1 with dots above. Is Euler better?
$endgroup$
– Daniel Mårtensson
Dec 17 '18 at 0:14
$begingroup$
The issue is not with the dots, it's that on the left you've written a sum $x_1'(t) + x_2'(t) + x_3'(t)$ rather than a vector $(x_1'(t), x_2'(t), x_3'(t))$. If I understand correctly, $x$ is a vector-valued function with component functions $x_1, x_2$, and $x_3$. The dot notation is fine.
$endgroup$
– littleO
Dec 17 '18 at 0:16
$begingroup$
Okej! Maybe I should change. Who is fastest to compute, Euler or RK4?
$endgroup$
– Daniel Mårtensson
Dec 17 '18 at 0:19
2
$begingroup$
Euler's method is easier to implement, but RK4 is much more accurate. I suspect that RK4 will be faster because you will be able to use a larger stepsize to achieve the same accuracy. There are more sophisticated methods such as RK45 that use adaptive stepsizes, and also implicit methods that are useful for "stiff" ODEs (for which explicit methods like Euler or RK4 might fail). You can implement RK4 pretty easily, but, using an ODE library is probably a good way to go.
$endgroup$
– littleO
Dec 17 '18 at 0:31
|
show 14 more comments
$begingroup$
I'm going to solve a ODE system on the form:
$$dot x(t) = f(x(t),u(t))$$
Where an example of the system migth look like:
$$(dot x_1(t) ,dot x_2(t) ,dot x_3(t))= a x_1(t) + b x_2 (t) + c x_3 (t) + d u(t) e x_2 (t) + f u(t) g x_1(t) + h sin(x_3(t))$$
The parameters $a,b,c,d,e,f,g,h$ are known and $x_1,x_2,x_3,dot x_1,dot x_2,dot x_3$ are known for $t = 0$ and $u$ are known $forall t$. Also $u$ is constant $forall t$.
So is there a way to to find $x_1,x_2,x_3$ by using linear algebra? I just got started with Armadillo and C++, then I realize that Armadillo does not have and ODE solver. But Armadillo is optimized for linear algebra.
ordinary-differential-equations simulation
$endgroup$
I'm going to solve a ODE system on the form:
$$dot x(t) = f(x(t),u(t))$$
Where an example of the system migth look like:
$$(dot x_1(t) ,dot x_2(t) ,dot x_3(t))= a x_1(t) + b x_2 (t) + c x_3 (t) + d u(t) e x_2 (t) + f u(t) g x_1(t) + h sin(x_3(t))$$
The parameters $a,b,c,d,e,f,g,h$ are known and $x_1,x_2,x_3,dot x_1,dot x_2,dot x_3$ are known for $t = 0$ and $u$ are known $forall t$. Also $u$ is constant $forall t$.
So is there a way to to find $x_1,x_2,x_3$ by using linear algebra? I just got started with Armadillo and C++, then I realize that Armadillo does not have and ODE solver. But Armadillo is optimized for linear algebra.
ordinary-differential-equations simulation
ordinary-differential-equations simulation
edited Dec 17 '18 at 0:20
Daniel Mårtensson
asked Dec 17 '18 at 0:08
Daniel MårtenssonDaniel Mårtensson
939416
939416
$begingroup$
The example system seems to be written incorrectly. On the left, you should have $(x_1'(t), x_2'(t), x_3'(t))$. You could implement your own ODE solver (using a method like RK4), or alternatively you could probably find a C++ library that provides an ODE solver that you can use. Here's a thread with some library suggestions: stackoverflow.com/questions/7622286/…
$endgroup$
– littleO
Dec 17 '18 at 0:12
$begingroup$
I'm used to write the x_1 with dots above. Is Euler better?
$endgroup$
– Daniel Mårtensson
Dec 17 '18 at 0:14
$begingroup$
The issue is not with the dots, it's that on the left you've written a sum $x_1'(t) + x_2'(t) + x_3'(t)$ rather than a vector $(x_1'(t), x_2'(t), x_3'(t))$. If I understand correctly, $x$ is a vector-valued function with component functions $x_1, x_2$, and $x_3$. The dot notation is fine.
$endgroup$
– littleO
Dec 17 '18 at 0:16
$begingroup$
Okej! Maybe I should change. Who is fastest to compute, Euler or RK4?
$endgroup$
– Daniel Mårtensson
Dec 17 '18 at 0:19
2
$begingroup$
Euler's method is easier to implement, but RK4 is much more accurate. I suspect that RK4 will be faster because you will be able to use a larger stepsize to achieve the same accuracy. There are more sophisticated methods such as RK45 that use adaptive stepsizes, and also implicit methods that are useful for "stiff" ODEs (for which explicit methods like Euler or RK4 might fail). You can implement RK4 pretty easily, but, using an ODE library is probably a good way to go.
$endgroup$
– littleO
Dec 17 '18 at 0:31
|
show 14 more comments
$begingroup$
The example system seems to be written incorrectly. On the left, you should have $(x_1'(t), x_2'(t), x_3'(t))$. You could implement your own ODE solver (using a method like RK4), or alternatively you could probably find a C++ library that provides an ODE solver that you can use. Here's a thread with some library suggestions: stackoverflow.com/questions/7622286/…
$endgroup$
– littleO
Dec 17 '18 at 0:12
$begingroup$
I'm used to write the x_1 with dots above. Is Euler better?
$endgroup$
– Daniel Mårtensson
Dec 17 '18 at 0:14
$begingroup$
The issue is not with the dots, it's that on the left you've written a sum $x_1'(t) + x_2'(t) + x_3'(t)$ rather than a vector $(x_1'(t), x_2'(t), x_3'(t))$. If I understand correctly, $x$ is a vector-valued function with component functions $x_1, x_2$, and $x_3$. The dot notation is fine.
$endgroup$
– littleO
Dec 17 '18 at 0:16
$begingroup$
Okej! Maybe I should change. Who is fastest to compute, Euler or RK4?
$endgroup$
– Daniel Mårtensson
Dec 17 '18 at 0:19
2
$begingroup$
Euler's method is easier to implement, but RK4 is much more accurate. I suspect that RK4 will be faster because you will be able to use a larger stepsize to achieve the same accuracy. There are more sophisticated methods such as RK45 that use adaptive stepsizes, and also implicit methods that are useful for "stiff" ODEs (for which explicit methods like Euler or RK4 might fail). You can implement RK4 pretty easily, but, using an ODE library is probably a good way to go.
$endgroup$
– littleO
Dec 17 '18 at 0:31
$begingroup$
The example system seems to be written incorrectly. On the left, you should have $(x_1'(t), x_2'(t), x_3'(t))$. You could implement your own ODE solver (using a method like RK4), or alternatively you could probably find a C++ library that provides an ODE solver that you can use. Here's a thread with some library suggestions: stackoverflow.com/questions/7622286/…
$endgroup$
– littleO
Dec 17 '18 at 0:12
$begingroup$
The example system seems to be written incorrectly. On the left, you should have $(x_1'(t), x_2'(t), x_3'(t))$. You could implement your own ODE solver (using a method like RK4), or alternatively you could probably find a C++ library that provides an ODE solver that you can use. Here's a thread with some library suggestions: stackoverflow.com/questions/7622286/…
$endgroup$
– littleO
Dec 17 '18 at 0:12
$begingroup$
I'm used to write the x_1 with dots above. Is Euler better?
$endgroup$
– Daniel Mårtensson
Dec 17 '18 at 0:14
$begingroup$
I'm used to write the x_1 with dots above. Is Euler better?
$endgroup$
– Daniel Mårtensson
Dec 17 '18 at 0:14
$begingroup$
The issue is not with the dots, it's that on the left you've written a sum $x_1'(t) + x_2'(t) + x_3'(t)$ rather than a vector $(x_1'(t), x_2'(t), x_3'(t))$. If I understand correctly, $x$ is a vector-valued function with component functions $x_1, x_2$, and $x_3$. The dot notation is fine.
$endgroup$
– littleO
Dec 17 '18 at 0:16
$begingroup$
The issue is not with the dots, it's that on the left you've written a sum $x_1'(t) + x_2'(t) + x_3'(t)$ rather than a vector $(x_1'(t), x_2'(t), x_3'(t))$. If I understand correctly, $x$ is a vector-valued function with component functions $x_1, x_2$, and $x_3$. The dot notation is fine.
$endgroup$
– littleO
Dec 17 '18 at 0:16
$begingroup$
Okej! Maybe I should change. Who is fastest to compute, Euler or RK4?
$endgroup$
– Daniel Mårtensson
Dec 17 '18 at 0:19
$begingroup$
Okej! Maybe I should change. Who is fastest to compute, Euler or RK4?
$endgroup$
– Daniel Mårtensson
Dec 17 '18 at 0:19
2
2
$begingroup$
Euler's method is easier to implement, but RK4 is much more accurate. I suspect that RK4 will be faster because you will be able to use a larger stepsize to achieve the same accuracy. There are more sophisticated methods such as RK45 that use adaptive stepsizes, and also implicit methods that are useful for "stiff" ODEs (for which explicit methods like Euler or RK4 might fail). You can implement RK4 pretty easily, but, using an ODE library is probably a good way to go.
$endgroup$
– littleO
Dec 17 '18 at 0:31
$begingroup$
Euler's method is easier to implement, but RK4 is much more accurate. I suspect that RK4 will be faster because you will be able to use a larger stepsize to achieve the same accuracy. There are more sophisticated methods such as RK45 that use adaptive stepsizes, and also implicit methods that are useful for "stiff" ODEs (for which explicit methods like Euler or RK4 might fail). You can implement RK4 pretty easily, but, using an ODE library is probably a good way to go.
$endgroup$
– littleO
Dec 17 '18 at 0:31
|
show 14 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3043375%2fis-there-a-way-to-solve-differential-equation-dot-x-fx-u-with-linear-alge%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3043375%2fis-there-a-way-to-solve-differential-equation-dot-x-fx-u-with-linear-alge%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
The example system seems to be written incorrectly. On the left, you should have $(x_1'(t), x_2'(t), x_3'(t))$. You could implement your own ODE solver (using a method like RK4), or alternatively you could probably find a C++ library that provides an ODE solver that you can use. Here's a thread with some library suggestions: stackoverflow.com/questions/7622286/…
$endgroup$
– littleO
Dec 17 '18 at 0:12
$begingroup$
I'm used to write the x_1 with dots above. Is Euler better?
$endgroup$
– Daniel Mårtensson
Dec 17 '18 at 0:14
$begingroup$
The issue is not with the dots, it's that on the left you've written a sum $x_1'(t) + x_2'(t) + x_3'(t)$ rather than a vector $(x_1'(t), x_2'(t), x_3'(t))$. If I understand correctly, $x$ is a vector-valued function with component functions $x_1, x_2$, and $x_3$. The dot notation is fine.
$endgroup$
– littleO
Dec 17 '18 at 0:16
$begingroup$
Okej! Maybe I should change. Who is fastest to compute, Euler or RK4?
$endgroup$
– Daniel Mårtensson
Dec 17 '18 at 0:19
2
$begingroup$
Euler's method is easier to implement, but RK4 is much more accurate. I suspect that RK4 will be faster because you will be able to use a larger stepsize to achieve the same accuracy. There are more sophisticated methods such as RK45 that use adaptive stepsizes, and also implicit methods that are useful for "stiff" ODEs (for which explicit methods like Euler or RK4 might fail). You can implement RK4 pretty easily, but, using an ODE library is probably a good way to go.
$endgroup$
– littleO
Dec 17 '18 at 0:31