how can i get all i for loop. the output only give me the last iterations. below are my coding.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
case 2 %newton
d = (get(handles.enterfunction,'string'));
syms x;
f = inline(d);
z = diff(f(x));
f1 = inline(z);
x0= str2num(get(handles.initialvalue,'string'));
tol = str2double(get(handles.tolerance,'string'));
max = str2double(get(handles.max,'string'));
for u=0:10000
y=x;
x=y-[f(x)/f1(x)];
if abs((y-x)/x) < tol
x=y;
break
end
end
x = num2str(x);
u = num2str(u);
display = [ u x f(x)];
set(handles.uitable5,'data',display);
set(handles.roots,'string',x);
set(handles.iterations,'string',u);
drawnow()
3 comentarios
Rik
el 7 de Oct. de 2021
If you want to add elements to a table, you will have to add them. What you're currently doing is overwriting all your variables with the new values. Which exact values do you want to save?
Respuestas (1)
Image Analyst
el 7 de Oct. de 2021
There is no "i" in the code that I noticed. Which is good because we don't recommend using i as a variable since i is the imaginary constant sqrt(-1).
But in general to save a variable into an array you need to index it with the loop iterator value.
for k = 1 : 10
myVariable(k) = rand(1); % Or whatever. Notice the (k) which will make myVariable a vector.
end
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!