0

I am trying to use Matlab to solve a problem which has two separate differential equations that I want to return the values for over time in one giant plot.

For Example the first portion I want to do is:

ainitial = 0;
arange=[0 2];
[a,A] = ode45(@rkfunc, arange, ainitial);

Then I would like to start the next ode45 portion based on the last A value, so I try to set it as binitial.

binitial = A(end);
brange=[2 4];
[b,B] = ode45(@rkfunc, brange, binitial);

Then I would like to combine and plot the answers from [a,A] and [b,B] together into one giant plot, but I'm not sure how to go about doing that.

Any help would be appreciated.

Note: Edited to show binitial = A(end) instead of B(end) which fixes the numbers not overlapping from A(end) and the start of B.

obizues
  • 1,473
  • 5
  • 16
  • 30
  • I should note I have tried doing: plotOutput = [A B]; plot(plotOutput, '-o') - and that plots both on the same graph, but not in one straight line with the same color, and the end of A does not start the beginning of B. – obizues Apr 20 '18 at 18:21
  • it is declared as rkfunc(t,T) – obizues Apr 20 '18 at 18:28
  • @NickyMattsson, also fixed a typo to use A(end) instead of B(end) – obizues Apr 20 '18 at 18:30
  • 1 dimensional numbers. – obizues Apr 20 '18 at 18:38
  • RKFUNC returns a vector of length 0, but the length of initial conditions vector is 1. The vector returned by RKFUNC and the initial conditions vector must have the same number of elements. – obizues Apr 20 '18 at 18:58
  • @NickyMattsson, now since I've done that, it no longer allows me to run my previously working matlab file. – obizues Apr 20 '18 at 19:01
  • You are concatenating the vectors wrongly, which you would realise if you checked the size of `A` and the size of `B`. – Nicky Mattsson Apr 20 '18 at 19:04
  • Why not just `plot(a,A,'-ob',b,B,'-ob')` to plot both pieces in the same graph? – Lutz Lehmann Apr 20 '18 at 21:05

1 Answers1

0

To concatenate two differently sized vectors you should use the syntax:

[A;B]

not

[A B]
obizues
  • 1,473
  • 5
  • 16
  • 30