# Double for loop is a problem ??? Any help, I can't find the right results when using the second for loop!!!!!

2 views (last 30 days)
Hello, I have to use two for loops in my code to calculate the matrix c, xp and yp. The first one concerning the parameter rr and the second for xxb.
To cheek my loops if works well, I compare the values of C and xp for yp when I use only the foo loop for rr for fixed values of xxp. But for some values of xxb I don't find the right results. For exemple , for xxb=0.05, and for 0.1, and for 0.15 the resuls not the same for the two cases.
Any Idea??? Thank you in advance,
Here is below my code:
xb=-5:0.05:5;
xxb=xb';% column vector
dr=0.01;
r=0:dr:5;
rr=r;% row vector
R=0.05;
for j=1:length(xxb);
for m=1:length(rr);
a(j)=2.*xxb(j);
c(j,m)=xxb(j).^2+rr(m).^2-R.^2;
xp(j,m)=c(j,m)./a(j);
yp(j,m)=R.^2-((((2.*c(j,m))-(a(j).^2))./(2.*a(j))).^2);
end
end
the end of code:
For exemple
using two for loop For the firt values of arrow of index 102 corresponding to the xxb=0.05:
-1,82145964977565e-17
9,99999999999816e-05
0,000399999999999982
0,000899999999999982
0,00159999999999998
0,00249999999999998
0,00359999999999998
0,00489999999999998
..........
using one for loop for xxb=0.05
0
9,99999999999998e-05
0,000400000000000000
0,000900000000000000
0,00160000000000000
0,00250000000000000
0,00360000000000000
..................
Thank you . I posted all my code in new way under the below question if you can help me .
Condition if on the elements of matrix in two For loop doesn't work