Storing Data From a For Loop

3 visualizaciones (últimos 30 días)
Faris Amzar Mohamad Azrai
Faris Amzar Mohamad Azrai el 2 de Jun. de 2020
Comentada: TADA el 4 de Jun. de 2020
How can I store all the results from the Loop? I keep getting the final value only.
D_c = 1:1:80;
L_c = 120;
C_s1c = 2.5e6;
C_01c = 2e6;
x = linspace(0,120,100);
xi = 0.1;
precision = 0.0001;
dc = 0;
my_root = [];
for i = 1:length(D_c)
dc = D_c(i);
df_c = @(x) (2.*x * C_s1c)./(2*sqrt(dc^2 + x.^2))-C_01c;
df_c2 = @(x) (dc^2 .* C_s1c)./((x.^2 + dc^2).^1.5);
[root] = newraph(df_c, df_c2, xi, precision);
end

Respuesta aceptada

TADA
TADA el 2 de Jun. de 2020
Assuming your Newton-Raphson method returns a scalar:
D_c = 1:1:80;
L_c = 120;
C_s1c = 2.5e6;
C_01c = 2e6;
x = linspace(0,120,100);
xi = 0.1;
precision = 0.0001;
dc = 0;
my_root = [];
root = zeros(size(D_c));
for i = 1:length(D_c)
dc = D_c(i);
df_c = @(x) (2.*x * C_s1c)./(2*sqrt(dc^2 + x.^2))-C_01c;
df_c2 = @(x) (dc^2 .* C_s1c)./((x.^2 + dc^2).^1.5);
root(i) = newraph(df_c, df_c2, xi, precision);
end
  2 comentarios
Faris Amzar Mohamad Azrai
Faris Amzar Mohamad Azrai el 2 de Jun. de 2020
Thanks! It helps alot
TADA
TADA el 4 de Jun. de 2020
cheers

Iniciar sesión para comentar.

Más respuestas (0)

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!

Translated by