my code is this
`
x0=input('Enter first guess (Must be grater than 0): ');
e=input('Enter the desired telorance : ');
n=input(['Enter the desired number of ' ...
'Iteration (Must be grater than 0): ']);
for Q=[0.0001,0.0002,0.0005,0.001,0.002,0.005,0.01,0.02]
for Re=[10000,20000,50000,100000,200000,500000,1000000]
syms f
t=(1:n);
eq=(-0.869*log((Q./3.7) + (2.523./(Re*sqrt(f))))).^-2;
g=@(f) (-0.869*log((Q./3.7) + (2.523./(Re*sqrt(f))))).^-2;
dg=diff((-0.869*log((Q./3.7) + (2.523./(Re*sqrt(f))))).^-2);
g0=eval(subs(dg,f,x0));
if abs(g0)<1
a=(['The differential of first guess is less than one' ...
'\n\nabs(g0)= %4.8f\n\n']);
fprintf(a,abs(g0));
else
disp('The differential of first guess is more than one')
continue
end
assume(f,'clear')
for i=1:n
x1=g(x0);
fprintf('x%d = %.8f\n',i,x1)
x2(1,i)=x1 %this is the part Im having problem with
x1=g(x0);
if abs(x1-x0)<e
break
end
x0=x1;
end
end
end
`
I want to add some calculated data to a matrix each time it loops but with out overwriting the old data since I dont know how many numbers Im going to get (it depends on the user input) I need to creat a matrix to put all numbers into it and its going to be a 1 row and (I dont know how many) Columns
when I used this code based on the number of n from the user I get a 1 row and n Column matrix and then It fills by it self until the matrix reach the n Columns then it overwrites the first one
x2 =
0.0198 0.0333 0.0307
x4 = 0.03110199
x2 =
0.0198 0.0333 0.0307 0.0311
The differential of first guess is less than one
abs(g0)= 0.11126141
x1 = 0.02554462
x2 =
0.0255 0.0333 0.0307 0.0311