MATLAB Answers

How to define a continuous range?

13 views (last 30 days)
Yuhong Jin
Yuhong Jin on 27 Nov 2019
Answered: Chidvi Modala on 3 Jan 2020
Here I defined a range for dy from 0.5 to 5 using
dy = 0.5:0.1:5
The script works slowly and need to wait for a long time for it to produce a graph
If I used another way like below trying to define a continuous range:
dy >=0.5 & dy <=5
or
dy >=0.5 && dy <=5
Matlab produces errors saying
Invalid use of operator.
My full script is below:
syms x1 y1 x2 y2
i=1;
for dy=0.5:0.1:5
M(i,1) = dy;
f = [5.*x1-6.*y1+1+0.5.*(x2-x1), 6.*x1-7.*y1+1+dy.*(y2-y1), 5.*x2-6.*y2+1+0.5.*(x1-x2), 6.*x2-7.*y2+1+dy.*(y1-y2)];
v = [x1,y1,x2,y2];
R0 = jacobian(f,v);
d0 = eig(R0);
dmax = [max(d0)]
M(i,2) = dmax;
i = i+1;
end
plot(M(:,1),M(:,2))
What should I do if I want to define a continuous range and improve the working speed of the script?
Thanks in advance.

  0 Comments

Sign in to comment.

Answers (1)

Chidvi Modala
Chidvi Modala on 3 Jan 2020
If you can provide the time it is taking to plot the graph by using tic and toc, it will be helpful. Because it is taking just 3s for me to run the entire script.

  0 Comments

Sign in to comment.

Sign in to answer this question.


Translated by