From: John Doe on
Hello
I am completely new to MatLAB, but I have read a few tutorials. I have some troubles with refining my plots where c-circles and t-tangents. Problems is that circles appear to not end at their intersection points but continue somehow to 500 (I know that I have defined x as 0:1:500 but if I change that it comes with error). I had 3 questions
- How can I force circles to "end" at intersection?
- How can I "cut" my lines/tangents so they only go to.. lets say 300
- How can I change colors of the plots so t1 and c1 and so on have same color?

Here is my function, it works fine, but need some refining

-----------------------------------------------------
x = 0:1:500;

c1 = (-x.^2+15.*x-20.47503).^(1/2);
c2=(-x.^2+42.42.*x-196.736).^(1/2);
c3=(-x.^2+143.14.*x-2462.6).^(1/2);
c4=(-x.^2+307.03.*x-12851.5).^(1/2);
c5=(-x.^2+588.28.*x-48828).^(1/2);

t1=1.342.*x;
t2=1.134.*x;
t3=1.039.*x;
t4=0.913.*x;
t5=0.879.*x;

plot(x,c1,x,c2,x,c3,x,c4,x,c5,x,t1,x,t2,x,t3,x,t4,x,t5)
xlabel('Principal Stresses [kPa])');
ylabel('Shear Stress');
title('Non-linear Mohr-Coulomb failure envelope for small stresses');
axis([0 500 0 400])
grid on
-----------------------------------------------------

Thanks in advance
From: Leiko D on
The quick and dirty way would be to simply define a separate x for each of your circles depending on their radius/intersection. The following are approximate x values from your plot.

ex:
x5 = 100:490;
c5 = (-x5.^2+588.28.*x5-48828).^(1/2);

And so on for the other circles (x4 = ... c4 = ..).

You can use x = 1:300; for your tangent lines since you now have defined new x values for the circles.

You have to specify colors if you want the lines to come out with specific colors. You can use b, r, y, m, c, g for simple colors.

ex:

figure(2)
hold on
plot(x5,c5,'b',x,t5,'b') % b = blue
plot(x4,c4,'g',x,t4,'g') % g = green
% repeat similar plot lines for the other circles
xlabel('Principal Stresses [kPa])');
ylabel('Shear Stress');
title('Non-linear Mohr-Coulomb failure envelope for small stresses');
axis([0 500 0 400])
grid on


As you get more comfortable with Matlab you might want to use arrays to define the radius and intersection of each of the circles. That way you won't have to define a new X for each of the circles and can do this in a loop.

Good luck :)