Multiple plots starting from different points in one graph

7 views (last 30 days)
Hello everyone and thanks in advance for reading my post.
I am struggling a bit with my code. What I want to do is to use 3 different equations and plot some graphs. However I can't make these three equation get into the same graph (in different positions). For example I want for x = (-1,-0.5) to use psi1, for x = (-0.5,0.5) psi2 and psi3 for x = (0.5,1), and then do it for multiple plots (which is the goal).
To make more clear how this code 'should' work, by entering a value for g (it is better to enter 10 if you want to check it), there should be 4 graphs, each one for a different value of k, where k is the solution of an equation f(k) = 0. I have attached both my function and my main code to this post.
Thanks a lot once again.
  2 Comments
dpb
dpb on 24 Nov 2013
To plot various lines is a couple of different ways -- the simplest is probably to simply build an X,Y pairing for each respectively and then call plot with the whole set.
x1=[-1 :0.1:-0.5]'; ps1=f(x1);
x2=[-0.5:0.1: 0.5]'; ps2=f(x2);
x3=[ 0.5:0.1: 1.0]'; ps3=f(x3);
plot(x1,ps1,'b',x2,ps2,'r',x3,ps3,'g')
Alternatively you can draw the first, use xlim to set the range to something at least as large as the range of x overall and then plot each individually.
plot(x1,ps1,'b')
xlim([min([x1(1) x2(1) x3(1) max([x1(end) x2(end) x3(end)])
plot(x2,ps2,'r')
plot(x3,ps3,'g')
Essentially an infinite number of perturbations on the above themes is possible... Alternatively, you can build multiple X,Y vectors and stack them up in a call Then the axes limits will span the range

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!