why is contents of array accidentally converted during for loop
Show older comments
Hi, I solve a equation to find its roots.
the equation is below.
x**3 + a*x**2 + 2*x + 3 = 0
the code is below.
function spp20171212a(amin,amax,imax)
aa=linspace(amin,amax,imax);
r1=zeros(1,imax);
r2=zeros(1,imax);
r3=zeros(1,imax);
for i=1:imax
a=aa(i);
rr=roots([1 a 2 3]);
r1(i)=rr(1);
r2(i)=rr(2);
r3(i)=rr(3);
end
plot(aa,real(r1),'k',aa,imag(r1),'r',...
aa,real(r2),'k',aa,imag(r2),'r',...
aa,real(r3),'k',aa,imag(r3),'r')
end
Attached is the result of this code.
But the lines on the figure connect other lines.
Why is the contents of array changed within for loop in Matlab?
Thanks
Accepted Answer
More Answers (0)
Categories
Find more on コマンドの入力 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!