%% Plot Region of Attraction
for k=1:360
xra(k)=2*cos(2*pi*k/360);
yra(k)=2*sin(2*pi*k/360);
end
figure(1)
p1=plot(xra,yra,'--r')
title('Initial Condition with radius ')
xlabel('x1(t)')
ylabel('x2(t)')
grid
axis(2.5*[-1 1 -1 1])
hold on
%% Plot Initial Circle
for k=1:360
xc(k)=ro*cos(2*pi*k/360); %Projection on x1
yc(k)=ro*sin(2*pi*k/360); %Projection on x2
end
figure(1)
p2=plot(xc,yc,'--k')
%% Run Simulation for N different initial conditions
for k =1:N
x1_o=ro*cos(2*pi*k/10+pi/6); %Projection on x1
x2_o=ro*sin(2*pi*k/10+pi/6); %Projection on x2
%% Simulation Linear Model
sim('sim_nonlinear_new.slx')
%states
x1=x(:,1);
x2=x(:,2);
scatter(x1_o,x2_o,100,'ok','filled') %Plot initial condition
plot(x1,x2) %Plot trajectory
drawnow;
legend([p1 p2],{'First','Second'});
end
hold off
I have above code for region of attraction circle and intial circle. I want to be able to display with a line drawing out and radius of the two circles. Please help

 Réponse acceptée

Star Strider
Star Strider le 11 Juin 2019

1 vote

You did not define ‘ro’.
When you do, you can plot the radius easily as:
plot([0 xra(45)], [0 yra(45)], '-b', [0 xc(135)],[0 yc(135)],'-g')
after the second loop. Choose whatever index you want to define the radius lines.
I would also use:
axis equal
so your circles don’t look like elipses.

5 commentaires

jeet Mehta
jeet Mehta le 11 Juin 2019
thanks for that , i have fixed the axis and have define it is showing the line. But also if i wana display the radius at the circle saying it is R=1.5 or any values how do i do it .
% text(xra(1,45), yra(2,45), '$R\ =\ 1.5$','Interpreter','latex')
% text(xra(1,120), yra(1,120), '$R\ =\ 2.0$','Interpreter','latex')
I have tried this and it dosent work . Please guide
jeet Mehta
jeet Mehta le 11 Juin 2019
@star strider
As always, my pleasure.
I am not certain what doesn’t work, unless it is a problem with the LaTeX interpreter.
Also, you are plotting both radius values using the same circle designation (the ‘xra’, ‘yra’ circle).
Try this:
text(xc(1,45), yc(2,45), '$R\ =\ 1.5$','Interpreter','latex')
text(xra(1,120), yra(1,120), '$R\ =\ 2.0$','Interpreter','latex')
Without the LaTeX interpreter:
text(xc(1,45), yc(2,45), 'R = 1.5')
text(xra(1,120), yra(1,120), 'R = 2.0')
If you want to change to display a different radius, just edit the text within the single quotes.
jeet Mehta
jeet Mehta le 11 Juin 2019
Thank you i did relaised that and fixed it yesterday . Thanks heaps really appreciate
Star Strider
Star Strider le 11 Juin 2019
As always, my pleasure.

Connectez-vous pour commenter.

Plus de réponses (1)

KSSV
KSSV le 11 Juin 2019

0 votes

YOu can display radius of the circle like below:
th = linspace(0,2*pi) ;
R = 1. ; % REadius of Circle
C = [0. 0.] ; % cneter of circle
x = C(1)+R*cos(th) ;
y = C(2)+R*sin(th) ;
plot(x,y)
hold on
plot([C(1) x(1)],[C(2) y(1)])

2 commentaires

jeet Mehta
jeet Mehta le 11 Juin 2019
It giving me error saying its bound to index 1 . Can u please have a look at the code above and suggest
KSSV
KSSV le 11 Juin 2019
The above code doesn't show any error. It is wokring fine unless you make some changes.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by