How to define a continuous range?

26 次查看(过去 30 天)
Yuhong Jin
Yuhong Jin 2019-11-27
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.

回答(1 个)

Chidvi Modala
Chidvi Modala 2020-1-3
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.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by