Plotting multiple curves using ODE45
I am a beginner to using MATLAB, and I need a lot of help to understand what to do here.
I would like to plot multiple curves using different initial conditions to my system of ODEs.
Here is my code:
f = @(t,x) [-1*x(1)-x(3)*x(3);2*x(2);x(3)-x(2)*x(2)];
[t,xa] = ode45(f,[0 5],[-1 0 0]);
plot3(xa(:,1),xa(:,2),xa(:,3));
grid on
title('Solution curve')
Does anybody know how I could do this?
It would make plotting phase planes a lot easier.
matlab
|
show 2 more comments
I am a beginner to using MATLAB, and I need a lot of help to understand what to do here.
I would like to plot multiple curves using different initial conditions to my system of ODEs.
Here is my code:
f = @(t,x) [-1*x(1)-x(3)*x(3);2*x(2);x(3)-x(2)*x(2)];
[t,xa] = ode45(f,[0 5],[-1 0 0]);
plot3(xa(:,1),xa(:,2),xa(:,3));
grid on
title('Solution curve')
Does anybody know how I could do this?
It would make plotting phase planes a lot easier.
matlab
You want to just plot phase planes in Matlab?
– dustin
Nov 13 '14 at 14:13
Yes, or even just have 3 curves from different initial conditions.
– Marc
Nov 13 '14 at 14:23
At least you should tell us what error message you receive from MATLAB.
– Evgeny
Nov 13 '14 at 14:23
Heck, I'll settle with 2 curves, but 3 would be excellent. There is no error code, I just don't know how to do it.
– Marc
Nov 13 '14 at 14:23
I have code that does this already will post at 950 when i get out of class
– dustin
Nov 13 '14 at 14:24
|
show 2 more comments
I am a beginner to using MATLAB, and I need a lot of help to understand what to do here.
I would like to plot multiple curves using different initial conditions to my system of ODEs.
Here is my code:
f = @(t,x) [-1*x(1)-x(3)*x(3);2*x(2);x(3)-x(2)*x(2)];
[t,xa] = ode45(f,[0 5],[-1 0 0]);
plot3(xa(:,1),xa(:,2),xa(:,3));
grid on
title('Solution curve')
Does anybody know how I could do this?
It would make plotting phase planes a lot easier.
matlab
I am a beginner to using MATLAB, and I need a lot of help to understand what to do here.
I would like to plot multiple curves using different initial conditions to my system of ODEs.
Here is my code:
f = @(t,x) [-1*x(1)-x(3)*x(3);2*x(2);x(3)-x(2)*x(2)];
[t,xa] = ode45(f,[0 5],[-1 0 0]);
plot3(xa(:,1),xa(:,2),xa(:,3));
grid on
title('Solution curve')
Does anybody know how I could do this?
It would make plotting phase planes a lot easier.
matlab
matlab
edited Nov 13 '14 at 14:21
dustin
6,70892968
6,70892968
asked Nov 13 '14 at 14:05
MarcMarc
12
12
You want to just plot phase planes in Matlab?
– dustin
Nov 13 '14 at 14:13
Yes, or even just have 3 curves from different initial conditions.
– Marc
Nov 13 '14 at 14:23
At least you should tell us what error message you receive from MATLAB.
– Evgeny
Nov 13 '14 at 14:23
Heck, I'll settle with 2 curves, but 3 would be excellent. There is no error code, I just don't know how to do it.
– Marc
Nov 13 '14 at 14:23
I have code that does this already will post at 950 when i get out of class
– dustin
Nov 13 '14 at 14:24
|
show 2 more comments
You want to just plot phase planes in Matlab?
– dustin
Nov 13 '14 at 14:13
Yes, or even just have 3 curves from different initial conditions.
– Marc
Nov 13 '14 at 14:23
At least you should tell us what error message you receive from MATLAB.
– Evgeny
Nov 13 '14 at 14:23
Heck, I'll settle with 2 curves, but 3 would be excellent. There is no error code, I just don't know how to do it.
– Marc
Nov 13 '14 at 14:23
I have code that does this already will post at 950 when i get out of class
– dustin
Nov 13 '14 at 14:24
You want to just plot phase planes in Matlab?
– dustin
Nov 13 '14 at 14:13
You want to just plot phase planes in Matlab?
– dustin
Nov 13 '14 at 14:13
Yes, or even just have 3 curves from different initial conditions.
– Marc
Nov 13 '14 at 14:23
Yes, or even just have 3 curves from different initial conditions.
– Marc
Nov 13 '14 at 14:23
At least you should tell us what error message you receive from MATLAB.
– Evgeny
Nov 13 '14 at 14:23
At least you should tell us what error message you receive from MATLAB.
– Evgeny
Nov 13 '14 at 14:23
Heck, I'll settle with 2 curves, but 3 would be excellent. There is no error code, I just don't know how to do it.
– Marc
Nov 13 '14 at 14:23
Heck, I'll settle with 2 curves, but 3 would be excellent. There is no error code, I just don't know how to do it.
– Marc
Nov 13 '14 at 14:23
I have code that does this already will post at 950 when i get out of class
– dustin
Nov 13 '14 at 14:24
I have code that does this already will post at 950 when i get out of class
– dustin
Nov 13 '14 at 14:24
|
show 2 more comments
1 Answer
1
active
oldest
votes
As far as I've understood, you have problems with plotting multiple trajectories. Here is your modified code for the case of two trajectories:
title('Solution curve')
f = @(t,x) [-1*x(1)-x(3)*x(3);2*x(2);x(3)-x(2)*x(2)];
[t,xa] = ode45(f,[0 5],[-1 0 0]);
plot3(xa(:,1),xa(:,2),xa(:,3));
grid on
hold on
[t,xa] = ode45(f,[0 5],[-2 0 0]);
plot3(xa(:,1),xa(:,2),xa(:,3));
However, it's better to use loops when you have many trajectories.
It would be better to have a script that calls a function that will do this. That way you dont need to write a loop every time you want the phase plane. One would aimple change the function definition and hit run.
– dustin
Nov 13 '14 at 14:40
I agree. The loop here is just for handling many initial conditions.
– Evgeny
Nov 13 '14 at 14:42
This code isn't working, it is only plotting one curve.
– Marc
Nov 13 '14 at 14:56
@Marc It works, but graphically, only one curve is visible because they are superimposed. For instance, add the'o'
option to one of the plot3 calls, e.g.plot3(xa(:,1),xa(:,2),xa(:,3),'o');
.
– Harry49
Sep 1 '17 at 11:14
add a comment |
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%2f1020072%2fplotting-multiple-curves-using-ode45%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As far as I've understood, you have problems with plotting multiple trajectories. Here is your modified code for the case of two trajectories:
title('Solution curve')
f = @(t,x) [-1*x(1)-x(3)*x(3);2*x(2);x(3)-x(2)*x(2)];
[t,xa] = ode45(f,[0 5],[-1 0 0]);
plot3(xa(:,1),xa(:,2),xa(:,3));
grid on
hold on
[t,xa] = ode45(f,[0 5],[-2 0 0]);
plot3(xa(:,1),xa(:,2),xa(:,3));
However, it's better to use loops when you have many trajectories.
It would be better to have a script that calls a function that will do this. That way you dont need to write a loop every time you want the phase plane. One would aimple change the function definition and hit run.
– dustin
Nov 13 '14 at 14:40
I agree. The loop here is just for handling many initial conditions.
– Evgeny
Nov 13 '14 at 14:42
This code isn't working, it is only plotting one curve.
– Marc
Nov 13 '14 at 14:56
@Marc It works, but graphically, only one curve is visible because they are superimposed. For instance, add the'o'
option to one of the plot3 calls, e.g.plot3(xa(:,1),xa(:,2),xa(:,3),'o');
.
– Harry49
Sep 1 '17 at 11:14
add a comment |
As far as I've understood, you have problems with plotting multiple trajectories. Here is your modified code for the case of two trajectories:
title('Solution curve')
f = @(t,x) [-1*x(1)-x(3)*x(3);2*x(2);x(3)-x(2)*x(2)];
[t,xa] = ode45(f,[0 5],[-1 0 0]);
plot3(xa(:,1),xa(:,2),xa(:,3));
grid on
hold on
[t,xa] = ode45(f,[0 5],[-2 0 0]);
plot3(xa(:,1),xa(:,2),xa(:,3));
However, it's better to use loops when you have many trajectories.
It would be better to have a script that calls a function that will do this. That way you dont need to write a loop every time you want the phase plane. One would aimple change the function definition and hit run.
– dustin
Nov 13 '14 at 14:40
I agree. The loop here is just for handling many initial conditions.
– Evgeny
Nov 13 '14 at 14:42
This code isn't working, it is only plotting one curve.
– Marc
Nov 13 '14 at 14:56
@Marc It works, but graphically, only one curve is visible because they are superimposed. For instance, add the'o'
option to one of the plot3 calls, e.g.plot3(xa(:,1),xa(:,2),xa(:,3),'o');
.
– Harry49
Sep 1 '17 at 11:14
add a comment |
As far as I've understood, you have problems with plotting multiple trajectories. Here is your modified code for the case of two trajectories:
title('Solution curve')
f = @(t,x) [-1*x(1)-x(3)*x(3);2*x(2);x(3)-x(2)*x(2)];
[t,xa] = ode45(f,[0 5],[-1 0 0]);
plot3(xa(:,1),xa(:,2),xa(:,3));
grid on
hold on
[t,xa] = ode45(f,[0 5],[-2 0 0]);
plot3(xa(:,1),xa(:,2),xa(:,3));
However, it's better to use loops when you have many trajectories.
As far as I've understood, you have problems with plotting multiple trajectories. Here is your modified code for the case of two trajectories:
title('Solution curve')
f = @(t,x) [-1*x(1)-x(3)*x(3);2*x(2);x(3)-x(2)*x(2)];
[t,xa] = ode45(f,[0 5],[-1 0 0]);
plot3(xa(:,1),xa(:,2),xa(:,3));
grid on
hold on
[t,xa] = ode45(f,[0 5],[-2 0 0]);
plot3(xa(:,1),xa(:,2),xa(:,3));
However, it's better to use loops when you have many trajectories.
answered Nov 13 '14 at 14:34
EvgenyEvgeny
4,63521022
4,63521022
It would be better to have a script that calls a function that will do this. That way you dont need to write a loop every time you want the phase plane. One would aimple change the function definition and hit run.
– dustin
Nov 13 '14 at 14:40
I agree. The loop here is just for handling many initial conditions.
– Evgeny
Nov 13 '14 at 14:42
This code isn't working, it is only plotting one curve.
– Marc
Nov 13 '14 at 14:56
@Marc It works, but graphically, only one curve is visible because they are superimposed. For instance, add the'o'
option to one of the plot3 calls, e.g.plot3(xa(:,1),xa(:,2),xa(:,3),'o');
.
– Harry49
Sep 1 '17 at 11:14
add a comment |
It would be better to have a script that calls a function that will do this. That way you dont need to write a loop every time you want the phase plane. One would aimple change the function definition and hit run.
– dustin
Nov 13 '14 at 14:40
I agree. The loop here is just for handling many initial conditions.
– Evgeny
Nov 13 '14 at 14:42
This code isn't working, it is only plotting one curve.
– Marc
Nov 13 '14 at 14:56
@Marc It works, but graphically, only one curve is visible because they are superimposed. For instance, add the'o'
option to one of the plot3 calls, e.g.plot3(xa(:,1),xa(:,2),xa(:,3),'o');
.
– Harry49
Sep 1 '17 at 11:14
It would be better to have a script that calls a function that will do this. That way you dont need to write a loop every time you want the phase plane. One would aimple change the function definition and hit run.
– dustin
Nov 13 '14 at 14:40
It would be better to have a script that calls a function that will do this. That way you dont need to write a loop every time you want the phase plane. One would aimple change the function definition and hit run.
– dustin
Nov 13 '14 at 14:40
I agree. The loop here is just for handling many initial conditions.
– Evgeny
Nov 13 '14 at 14:42
I agree. The loop here is just for handling many initial conditions.
– Evgeny
Nov 13 '14 at 14:42
This code isn't working, it is only plotting one curve.
– Marc
Nov 13 '14 at 14:56
This code isn't working, it is only plotting one curve.
– Marc
Nov 13 '14 at 14:56
@Marc It works, but graphically, only one curve is visible because they are superimposed. For instance, add the
'o'
option to one of the plot3 calls, e.g. plot3(xa(:,1),xa(:,2),xa(:,3),'o');
.– Harry49
Sep 1 '17 at 11:14
@Marc It works, but graphically, only one curve is visible because they are superimposed. For instance, add the
'o'
option to one of the plot3 calls, e.g. plot3(xa(:,1),xa(:,2),xa(:,3),'o');
.– Harry49
Sep 1 '17 at 11:14
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
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%2f1020072%2fplotting-multiple-curves-using-ode45%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
You want to just plot phase planes in Matlab?
– dustin
Nov 13 '14 at 14:13
Yes, or even just have 3 curves from different initial conditions.
– Marc
Nov 13 '14 at 14:23
At least you should tell us what error message you receive from MATLAB.
– Evgeny
Nov 13 '14 at 14:23
Heck, I'll settle with 2 curves, but 3 would be excellent. There is no error code, I just don't know how to do it.
– Marc
Nov 13 '14 at 14:23
I have code that does this already will post at 950 when i get out of class
– dustin
Nov 13 '14 at 14:24